poj 2965 The Pilots Brothers' refrigerator
来源:互联网 发布:xbmc使用教程网络硬盘 编辑:程序博客网 时间:2024/06/14 14:19
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 rowi 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/***实际这个题与1753非常类似,只是在1753代码基础上加上几步处理*/#include <iostream>#include <cstring>#include <cstdio>using namespace std;bool vis[5][5] = {{false}};bool flag = false;int step;int xx[16],yy[16];bool Judge(){ for(int i=1;i<=4;i++) { for(int j=1;j<=4;j++) { if(!vis[i][j]) return false; } } return true;}void Flip(int x,int y){ vis[x][y] = !vis[x][y]; for(int i=1;i<=4;i++) { vis[x][i] = !vis[x][i]; vis[i][y] = !vis[i][y]; }}void DFS(int x,int y,int deep){ if(deep == step) { flag = Judge(); return ; } if(flag || y == 5) return ; Flip(x,y); xx[deep] = x; yy[deep] = y; if(x < 4) DFS(x+1,y,deep+1); else DFS(1,y+1,deep+1); Flip(x,y); if(x < 4) DFS(x+1,y,deep); else DFS(1,y+1,deep);}int main(){ // freopen("in.txt","r",stdin); char ch; for(int i=1; i<=4; i++) { for(int j=1; j<=4; j++) { cin>>ch; if(ch == '-') vis[i][j] = true; } } for(step=1; step<=16; step++) { DFS(1,1,0); if(flag) break; } cout<<step<<endl; for(int i=0; i<step; i++) cout<<xx[i]<<" "<<yy[i]<<endl; return 0;}
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- poj 2965The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator 枚举
- POJ-2965-The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- POJ-2965-The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965:The Pilots Brothers' refrigerator
- Poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator(枚举)
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator 枚举
- POJ-2965-The Pilots Brothers' refrigerator
- 随机数的产生
- 第16周周四:GUI编程及文件对话框的使用
- 网站策划
- tomcat6 高级特性 阀(一)
- 连接设备上的有线
- poj 2965 The Pilots Brothers' refrigerator
- GC (二)Garbage Collection in Java
- 自动取款机的硬件组成
- 其实canvas真的很简单,复杂的部分其实是你的创意
- 天声人語 20150630
- 继往开来
- 第一次写个博客
- linux文件权限查看及修改(实用)
- Linux中解压rar 文件