poj1753 Flip Game 枚举+BFS
来源:互联网 发布:电视频道直播软件下载 编辑:程序博客网 时间:2024/05/29 13:23
#include<iostream>#include<queue>#include<cstdio>#include<cstring>using namespace std;struct st{ int cur;//当前格局 int choose;//已选了哪几个格子 int step;//步数}w,temp;const int res=((1<<16)-1);int dirt[4][2]={0,1,0,-1,1,0,-1,0};bool flag[res+1];//判重int BFS(){ queue<st>q; q.push(w); int x,y; while(!q.empty()) { w=q.front(); q.pop(); if(w.cur==0||w.cur==res) return w.step; for(int j=0;j<16;j++) { if(w.choose&(1<<j))//第j个格子已选过 continue; temp.choose=w.choose|(1<<j); if(flag[temp.choose]) continue; flag[temp.choose]=true; temp.step=w.step+1; temp.cur=w.cur^(1<<j); y=j%4; x=(j-y)/4; for(int k=0;k<4;k++) { int xx=x+dirt[k][0]; int yy=y+dirt[k][1]; if(xx<0||xx>=4||yy<0||yy>=4) continue; temp.cur^=(1<<(4*xx+yy)); } q.push(temp); } } return -1;}int main(){ char ch; int ans; while(cin>>ch) { w.cur=w.step=w.choose=0; if(ch=='w') w.cur++; memset(flag,false,sizeof(flag)); for(int i=1;i<16;i++) { cin>>ch; if(ch=='w') w.cur|=(1<<i); } ans=BFS(); if(ans>=0) printf("%d\n",ans); else printf("Impossible\n"); } return 0;}
- poj1753 Flip Game 枚举+BFS
- POJ1753,Flip Game,枚举,bfs都可以
- POJ1753--Flip Game(枚举)
- POJ1753:Flip Game(BFS、枚举、位运算)
- POJ1753 Flip Game DFS+枚举
- poj1753 Flip Game DFS,枚举
- POJ1753《Flip Game》方法:BFS+Bit
- poj1753 Flip Game BFS+位运算
- poj1753 Flip Game 状态压缩+bfs
- POJ1753 Flip Game(位压+BFS)
- 【POJ1753】Flip Game(位压缩+bfs)
- poj1753 Flip Game —— bfs
- #POJ1753#Flip Game(位运算+BFS)
- poj1753 Flip Game(枚举Enum+dfs)
- poj1753 Flip Game 枚举 暴力 递归
- (枚举初级+回溯)poj1753 Flip Game
- poj1753 Flip Game
- poj1753 Flip Game
- 很全面的视频编码格式表
- oracleDBA关于控制文件被移动的问题
- 一道面试题引发的思考
- 区分指针数组的好方法
- VirtualBox中VDI镜像的复制
- poj1753 Flip Game 枚举+BFS
- 秋雨寄相思
- 面试题整理-台阶问题
- 关于新导入的项目如何配置到以创建的tomcat上
- 引用与指针的区别总结
- Android Screen Monitor抓取真机屏幕
- 想你,但不爱你
- Agile Web Application Development with Yii 1.1 and PHP5 读后总结(1)简短介绍
- HDU 1084 What Is Your Grade?