POJ 1753Flip Game
来源:互联网 发布:现货电子交易软件 编辑:程序博客网 时间:2024/06/06 03:02
#include<cstring>#include<iostream>#include<algorithm>#include<queue>#include<map>#include<cstdio>#include <string>#define ll long longusing namespace std;int st,vis[(1 << 17)];int change(int x,int w){ x ^= (1 << w); if(w > 3) { x ^= (1 << (w - 4)); } if(w < 12) { x ^= (1 << (w + 4)); } if(w % 4) { x ^= (1 << (w - 1)); } if(w % 4 < 3) { x ^= (1 << (w + 1)); } return x;}int bfs(){ queue<pair<int,int> >q; pair<int,int>stt; stt.first = st,stt.second = 0; //cout << st << endl; q.push(stt); vis[st] = 1; if(st == 0 || st == 65535) return 0; while(!q.empty()) { pair<int,int> te = q.front(); q.pop(); for(int i = 0;i < 16;i++) { int now = change(te.first,i); if(now == 0 || now == 65535) return te.second + 1; if(vis[now]) continue; vis[now] = 1; q.push(make_pair(now,te.second + 1)); } } return -1;}int main(){string gg;while(cin >> gg){ memset(vis,0,sizeof(vis)); st = 0; for(int j = 0;j < 4;j++) { if(gg[j] == 'b') { st |= (1 << (j)); } } for(int i = 1;i < 4;i++) { char s[11]; scanf("%s",s); for(int j = 0;j < 4;j++) { if(s[j] == 'b') { st |= (1 << (i * 4 + j)); } } } //cout << st << endl; int ou = bfs(); if(ou == -1) cout << "Impossible\n"; else cout << ou << endl; } 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
- 【C/C++】知识回顾2
- Qt学习之给QPushButton添加菜单CustomContextMenu方法
- Linux 内存不足
- 蓝桥杯数独游戏——C语言版
- 2016年3月19日:如何让一个单网页自适应手机
- POJ 1753Flip Game
- 三层架构中使用实体类填充泛型集合代替DataTable解决方案(ASP.NET+C#)
- 设计模式之单例模式
- 六大排序算法c++实现
- 宋仲基太阳的后裔头像 撩到你了吗
- React-Native schema跳转
- POJ 2488A Knight's Journey(DFS)
- sql 的一些数据优化
- CentOS 7下autojump无法使用的可能原因