POJ 2956 The Pilots Brothers' refrigerator
来源:互联网 发布:复杂网络基础概论 编辑:程序博客网 时间:2024/05/29 07:52
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
Source
[Submit] [Go Back] [Status] [Discuss]
Home Page Go Back To top
- Source Code
#include <iostream>using namespace std;bool m[10][10], flag;int step;struct node{ int x, y;}A[65536+5];bool judge(){ for(int i=1;i<=4;i++) for(int j=1;j<=4;j++) if(m[i][j]) return 0; return 1;}void flip(int x, int y){ for(int i=1;i<=4;i++){ m[i][y]=!m[i][y]; m[x][i]=!m[x][i]; } m[x][y]=!m[x][y];}void dfs(int x, int y, int dep){ if(dep>=step){ flag=judge(); return ; } if(x>=5||flag) return ; A[dep].x=x; A[dep].y=y; flip(x,y); if(y<4) dfs(x,y+1,dep+1); else dfs(x+1,1,dep+1); flip(x,y); if(y<4) dfs(x,y+1,dep); else dfs(x+1,1,dep);}int main(){ char c; flag=0; for(int i=1;i<=4;i++) for(int j=1;j<=4;j++){ cin>>c; if(c=='+') m[i][j]=1; else m[i][j]=0; } for(step=0;step<=16;step++){ dfs(1,1,0); if(flag) break; } if(flag){ cout<<step<<endl; for(int i=0;i<step;i++){ cout<<A[i].x<<' '<<A[i].y<<endl; } } return 0;}
- POJ 2956 The Pilots Brothers' refrigerator
- 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 The Pilots Brothers' refrigerator(DFS)
- POJ 2965 The Pilots Brothers' refrigerator
- 警告: No mapping found for HTTP request with URI [] in DispatcherServlet with name
- maven update error:Cannot nest 'xxx/WEB-INF/classes' inside 'xxx'
- hdu 1007 平面最近点对 分治
- C语言修饰词之violate使用
- Linux系统工程师的必备素质
- POJ 2956 The Pilots Brothers' refrigerator
- Pjsip通信如何使用TCP协议
- spark配置文件加载的先后顺序
- AngularJS:何时应该使用Directive、Controller、Service?
- LocalBroadcastManager 的实现原理,还是 Binder?
- opencv Haartraining
- linux系统三大文本处理工具grep、sed及awk的简单介绍
- 【H5】html5的新增的标签和废除的标签
- InnoDB的compact行格式详解