POJ 1753 Flip Game
来源:互联网 发布:网络购彩恢复时间 编辑:程序博客网 时间:2024/05/22 14:08
链接:http://vjudge.net/problem/viewProblem.action?id=16122
赶时间,参考了别人的代码
#include <iostream>#include <cstring>using namespace std;int st,map[6][6];int dir[4][2] = {0,1,0,-1,1,0,-1,0};bool flag;void init(){ memset(map,0,sizeof(map)); flag = 0; for(int i = 1;i <= 4;++i) { for(int j = 1;j <= 4;++j) { char ch; cin>>ch; if(ch == 'b') map[i][j] = 1; } }}//判断是否到达成功状态bool isSuccess(){ int cmp = map[1][1]; for(int i = 1;i <= 4;++i) { for(int j = 1;j <= 4;++j) { if(map[i][j] != cmp) return false; } } return true;}//翻转对应区域void flip(int r,int c){ map[r][c] = !map[r][c]; for(int i = 0;i < 4;++i) { int t1 = r + dir[i][0]; int t2 = c + dir[i][1]; map[t1][t2] = !map[t1][t2]; }}void dfs(int r,int c,int cur){ if(cur == st) { if(isSuccess()) flag = 1; return; } if(flag || r == 5) return; //选择对当前位置翻转一次 flip(r,c); if(c < 4) dfs(r,c+1,cur+1); else dfs(r+1,1,cur+1); //选择对当前位置不翻转,翻转两次相当于回到原来的状态 flip(r,c); if(c < 4) dfs(r,c+1,cur); else dfs(r+1,1,cur); return;}void solve(){ //i 为翻转几次,对每一步穷举状态 for(int i = 0;i <= 16;++i) { st = i; dfs(1,1,0); if(flag) break; } if(flag) cout<<st<<endl; else cout<<"Impossible"<<endl;}int main(){ init(); solve(); return 0;}
0 0
- poj 1753 Flip Game
- poj 1753 Flip Game
- poj 1753 Flip Game
- poj 1753 Flip Game
- POJ 1753 Flip Game
- poj 1753 Flip Game
- poj 1753 Flip Game
- POJ-1753-Flip Game
- POJ 1753: Flip Game
- POJ 1753 Flip Game
- POJ 1753 Flip Game
- poj 1753 Flip Game
- poj 1753 Flip Game
- POJ 1753 Flip Game
- POJ-1753-Flip Game
- Poj 1753 Flip Game
- POJ 1753 Flip Game
- POJ-1753-Flip Game
- 微软SQL Server 2014疑难解析问题摘录
- Tour De Babel
- org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/ljt/hiberna
- linux操作命令:grep命令
- 程序员的十个层次 你属于哪一层?
- POJ 1753 Flip Game
- ios学习--网络请求
- 程序员教程---一些书
- You don't have permission to access /phpmyadmin/ on this server.
- 第十一讲
- 看完这20部电影,你可以去全球任何一家公司做董事长或总经理
- 数据挖掘十大经典算法
- hadoop各种输入方法(InputFormat)汇总
- 第十二讲