POJ 2965 The Pilots Brothers' refrigerator
来源:互联网 发布:js模块化怎么做 编辑:程序博客网 时间:2024/05/23 21:55
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
题意:就是要你把+号全部变成减号!并输出步骤
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int lock[4][4];int r[16],c[16];int flag,step;int isOpen(){ int i,j; for(i=0;i<4;i++) for(j=0;j<4;j++) if(!lock[i][j]) return 0; return 1;}void flip(int row,int col){ lock[row][col]=!lock[row][col]; for(int i=0;i<4;i++) lock[i][col]=!lock[i][col]; for(int j=0;j<4;j++) lock[row][j]=!lock[row][j];}void dfs(int row,int col,int deep){ if(deep==step){ flag=isOpen(); return ; } if(flag || row==4) return ; r[deep]=row; c[deep]=col; flip(row,col); if(col<3) dfs(row,col+1,deep+1); else dfs(row+1,0,deep+1); flip(row,col); if(col<3) dfs(row,col+1,deep); else dfs(row+1,0,deep);}int main(){ char ch; memset(lock,0,sizeof(lock)); for(int i=0;i<4;i++) for(int j=0;j<4;j++) { cin>>ch; if(ch=='-') lock[i][j]=1; else lock[i][j]=0; } for(step=0;step<=16;step++) { dfs(0,0,0); if(flag) break; } printf("%d\n",step); for(int i=0;i<step;i++) printf("%d %d\n",r[i]+1,c[i]+1); 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
- HDU3746-Cyclic Nacklace(KMP)
- 博客开业,文章首发-回顾曾经
- 利用RawSocket篡改UDP源地址
- 浏览文件系统
- MySQL插入数据时插入无效的列
- POJ 2965 The Pilots Brothers' refrigerator
- Delphi中判断文件是否为文本文件的函数
- JVM,JDK,JRE的理解
- C++语言笔记系列之二十——模版
- happens-before俗解
- C static 关键字
- IT学习方法
- HashMap遍历的两种方式
- 2-0. 整数四则运算(10)