博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2965 -- The Pilots Brothers' refrigerator
阅读量:7009 次
发布时间:2019-06-28

本文共 3302 字,大约阅读时间需要 11 分钟。

The Pilots Brothers' refrigerator
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 17620   Accepted: 6676   Special Judge

Description

The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator.

There are 16 handles on the refrigerator door. Every handle can be in one of two states: open or closed. The refrigerator is open only when all handles are open. The handles are represented as a matrix 4х4. You can change the state of a handle in any location [i, j] (1 ≤ i, j ≤ 4). However, this also changes states of all handles in row i and all handles in column j.

The task is to determine the minimum number of handle switching necessary to open the refrigerator.

Input

The input contains four lines. Each of the four lines contains four characters describing the initial state of appropriate handles. A symbol “+” means that the handle is in closed state, whereas the symbol “−” means “open”. At least one of the handles is initially closed.

Output

The first line of the input contains N – the minimum number of switching. The rest N lines describe switching sequence. Each of the lines contains a row number and a column number of the matrix separated by one or more spaces. If there are several solutions, you may give any one of them.

Sample Input

-+-----------+--

Sample Output

61 11 31 44 14 34 4 这个题用位运算搜索(枚举)即可,只不过多了一个打印路径。递归打印就行。
1 /*====================================================================== 2  *           Author :   kevin 3  *         Filename :   ThePilotsBrothersRefrigerator.cpp 4  *       Creat time :   2014-05-13 19:58 5  *      Description : 6 ========================================================================*/ 7 #include 
8 #include
9 #include
10 #include
11 #include
12 #include
13 #define clr(a,b) memset(a,b,sizeof(a))14 #define M (1<<17)15 using namespace std;16 int cnt[M],number;17 struct node18 {19 int x,y,n;20 }node[M];21 int dir[4][4]={22 0xf888,0xf444,0xf222,0xf111,23 0x8f88,0x4f44,0x2f22,0x1f11,24 0x88f8,0x44f4,0x22f2,0x11f1,25 0x888f,0x444f,0x222f,0x111f26 };27 void Print(int s)28 {29 if(number == node[s].n)30 return ;31 int t = node[s].n;32 Print(t);33 printf("%d %d\n",node[t].x+1,node[t].y+1);34 }35 int BFS(int num)36 {37 queue
pq;38 cnt[num] = 1;39 pq.push(num);40 while(!pq.empty()){41 int v = pq.front();42 pq.pop();43 for(int i = 0; i < 4; i++){44 for(int j = 0; j < 4; j++){45 int t = v^dir[i][j];46 if(t == 0x0000){47 cnt[t] = cnt[v];48 node[t] = {i,j,v};49 return cnt[t];50 }51 if(!cnt[t]){52 cnt[t] = cnt[v]+1;53 node[t] = {i,j,v};54 pq.push(t);55 }56 }57 }58 }59 return -1;60 }61 int main(int argc,char *argv[])62 {63 char str[6];64 while(cin>>str){65 clr(cnt,0);66 clr(node,0);67 number = 0;68 for(int i = 0; str[i]; i++){69 number = number << 1;70 if(str[i] == '+'){71 number |= 1;72 }73 }74 for(int i = 0; i < 3; i++){75 cin>>str;76 for(int j = 0; str[j]; j++){77 number = number << 1;78 if(str[j] == '+'){79 number |= 1;80 }81 }82 }83 int steps = BFS(number);84 printf("%d\n",steps);85 Print(0);86 printf("%d %d\n",node[0].x+1,node[0].y+1);87 }88 return 0;89 }
View Code

 

转载于:https://www.cnblogs.com/ubuntu-kevin/p/3727128.html

你可能感兴趣的文章
90%炒币者亏钱,区块链“撒币时代”结束了
查看>>
冬天来了,让Sleep System智能床垫帮你暖床!
查看>>
2017洛客大会成功落幕, 全球“洛客”开启“想象力时代”
查看>>
关于区块链革命你必须知道的事实
查看>>
开源 |蚂蚁金服启动分布式中间件开源计划,用于快速构建金融级云原生架构...
查看>>
Go语言之基准测试
查看>>
win10_x64更新错误解决: 安装一些更新时出现问题,但我们稍后会重试。如果持续出现这些问题,并且你想要搜索Web或联系支持人员以获取相关信息,以下信息可能会对你有帮助:...
查看>>
keepalived vrrp_script的一些实例配置
查看>>
《数字逻辑设计与计算机组成》一 3.4 减法器
查看>>
Chrome浏览器也开启Material Design风格
查看>>
《系统分析与设计方法及实践》一2.1 软件生命周期
查看>>
Oracle Logminer 日志挖掘
查看>>
印媒:全球科技巨头竞相角逐印度“智能城市”项目
查看>>
《Servlet和JSP学习指南》一2.2 隐藏域
查看>>
[干货]基础机器学习算法
查看>>
12月14日全球域名商解析量22强:爱名网升至十七
查看>>
全球域名商解析新增量20强:中国占据7个席位
查看>>
在python中获取当前位置所在的行号和函数名
查看>>
如何导出PPT内的所有图片做素材(IT实用技巧)
查看>>
定时自动启动任务crontab命令用法
查看>>