poj 1753 Flip Game
来源:互联网 发布:淘宝哪家饰品店好 编辑:程序博客网 时间:2024/06/06 17:33
先贴个BFS+位运算的代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;unsigned short q[65536],rear,top,step[65536];bool vis[65536];unsigned short temp;bool bfs(){ memset(q,0,sizeof(q)); memset(vis,0,sizeof(vis)); rear=top=0; q[top++]=temp; step[temp]=0; while(rear<top){ temp=q[rear++]; if(temp==0||temp==65535){ cout<<step[temp]<<endl; return true; } short i=0; for(;i<16;i++){ unsigned short ex=0; ex|=1<<i; if(i>3){ ex|=1<<(i-4); } if(i<12){ ex|=1<<(i+4); } if(i%4){ ex|=1<<(i-1); } if((i+1)%4){ ex|=1<<(i+1); } ex=ex^temp; if(!vis[ex]){ vis[ex]=true; q[top++]=ex; step[ex]=step[temp]+1; } } } return false;}int main(){ //freopen("D:\\INPUT.txt","r", stdin); short i=0; temp=0; for(;i<16;i++){ char c; cin>>c; //cout<<c<<endl; if(c=='b'){ temp|=(1<<i); } } if(!bfs()){ cout<<"Impossible\n";//"\b"打成"/n",WA } 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
- 设计模式(知识点)
- Lesson 17 继承与派生基础
- 快速排序 java版
- 根目录执行chmod -R 777 / 的补救方法
- 使用udev高效、动态地管理Linux设备文件
- poj 1753 Flip Game
- 黑马程序员 【】java学习之路——IO流使用解析
- 关于移动互联网的小思考
- 四、表空间、数据库对象
- 第八章 8.2.2节练习
- 关于Eclipse创建Android项目时,会多出一个appcompat_v7的问题
- 五、pl/sql块
- 异常处理
- 八、开发函数