POJ-2965-ThePilotsBrothers'refrigerator
来源:互联网 发布:天盾微信数据恢复工具 编辑:程序博客网 时间:2024/06/16 01:33
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
Northeastern Europe 2004, Western Subregion
#include<iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstring>using namespace std;bool Map[4][4];bool flag = false;int step, top = 0;struct node{ int x, y;}xt[20];void fold(int x, int y){ for(int i = 0; i<4; ++i) { Map[x][i] = !Map[x][i]; Map[i][y]= !Map[i][y]; } Map[x][y] = !Map[x][y];}int Make_sure(){ for(int i = 0; i<4; ++i) for(int j = 0; j<4; ++j) if(!Map[i][j])return false; return true;}void dfs(int x, int y, int s){ if(s==step) { flag = Make_sure(); return; } if(y==4) { ++x; y = 0; } if(x==4||flag)return; fold(x,y); xt[top].x = x; xt[top].y = y; ++top; dfs(x,y+1,s+1); fold(x,y); if(flag)return; --top; dfs(x,y+1, s);}int main(){ char s[6]; for(int i = 0; i<4; ++i) { scanf("%s", s); for(int j = 0; j<4; ++j) { if(s[j]=='+')Map[i][j] = 0; else Map[i][j] = 1; } } for(step = 0; step<=16;++step) { dfs(0,0,0); if(flag)break; } printf("%d\n", step); for(int i = 0; i<top; ++i) printf("%d %d\n",xt[i].x+1, xt[i].y+1); return 0;}
- POJ-2965-ThePilotsBrothers'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 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator 枚举
- mysql入门(1)--- SQL分类
- 在android中运行java main方法
- HDU 5747 Aaronson
- ios8以上 ble 实现 bt sink
- Android Camera 相机开发详解
- POJ-2965-ThePilotsBrothers'refrigerator
- Java 集合系列目录(Category)
- 如何防止用户重复提交
- Android studio 模块引用
- Ubuntu 配置 Nginx http2.0 支持 (二) 编译&配置Nginx 与 pagespeed
- 简述TCP和UDP协议并举例说明它们的区别
- Spring 框架初步学习
- Java之美[从菜鸟到高手演练]之atomic包的原理及分析
- Redis TTL命令