poj2965 The Pilots Brothers' refrigerator
来源:互联网 发布:淘宝双11充值红包退款 编辑:程序博客网 时间:2024/05/21 14:41
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 columnj.
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上略作修改
#include <iostream>#include <cstring>using namespace std;int a[6][6];int r[17],c[17];bool flag = false;int step;bool check(){for(int i=1;i<5;i++) for(int j=1;j<5;j++) if (a[i][j]!=1) return false; return true;}void flip(int row,int col){ a[1][col] = (a[1][col]+1)%2; a[2][col] = (a[2][col]+1)%2; a[3][col] = (a[3][col]+1)%2; a[4][col] = (a[4][col]+1)%2; a[row][1] = (a[row][1]+1)%2; a[row][2] = (a[row][2]+1)%2; a[row][3] = (a[row][3]+1)%2; a[row][4] = (a[row][4]+1)%2; a[row][col] = (a[row][col]+1)%2; return;}void sear(int row,int col,int deep){if(deep==step) { flag=check(); return; } if(flag||row==5)return; flip(row,col); r[deep] = row; c[deep] = col; if(col<4) sear(row,col+1,deep+1); else sear(row+1,1,deep+1); flip(row,col); if(col<4) sear(row,col+1,deep); else sear(row+1,1,deep); return;}int main(){ char b;memset(a,0,sizeof(a)); for(int i=1;i<5;i++) for(int j=1;j<5;j++) { cin>>b; if(b=='-') a[i][j] = 1; } for(step=0;step<=16;step++){ sear(1,1,0); if(flag) break; } if(flag){ cout<<step<<endl; for(int j=0;j<=17;j++) if(c[j]!=0&&r[j]!=0) cout<<r[j]<<" "<<c[j]<<endl; } else cout<<"Impossible"<<endl; return 0;}
- POJ2965 The Pilots Brothers' refrigerator
- POJ2965----The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965--The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- The Pilots Brothers' refrigerator Poj2965
- POJ2965-The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965-The Pilots Brothers' refrigerator
- poj2965-The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers\' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965 The Pilots Brothers' refrigerator 枚举
- poj2965——The Pilots Brothers' refrigerator
- gentoo with gnome (来自 http://blog.chinaunix.net/uid-11009175-id-3549857.html)
- Break和continue区别
- 视图view(重点)
- POJ2845_01000001
- DFS_ZOJ1002
- poj2965 The Pilots Brothers' refrigerator
- sdfa
- iOS开发之视图控制器(UIViewController)
- 变幻线
- vs devenv命令用法
- zoj 2339 Hyperhuffman 哈夫曼编码 (4-C)
- NYOJ - 311 《完全背包》 【完全恰满背包】
- PHP版本VC6与VC9、Thread Safe与None-Thread Safe等的区别
- webview js 交互问题