POJ 2965:The Pilots Brothers' refrigerator
来源:互联网 发布:windows同步时间出错 编辑:程序博客网 时间:2024/05/18 18:03
这个题目的解法与poj:1753差不多,只是我添加了一个链表来记录每次操作的步骤
我就直接贴代码了
#include <iostream>#include <queue>#include <list>using namespace std;#define SIZE 4#defineMAX65536int flip[]={63624,62532,61986,61713,36744,20292,12066,7953,35064,17652,8946,4593,34959,17487,8751,4383};queue<int> myqueue;struct{int i;int prior;}record[MAX];int main(){int answer[SIZE*SIZE];int step[MAX];bool flag[MAX];memset(step,0,MAX);memset(flag,false,MAX);int stat = 0;int nextstat=0;int i,j,tmp1;char c;for (i=0;i<SIZE*SIZE;++i){cin>>c;c=='+'?(stat<<=1)++:stat<<=1;}flag[stat]=0;step[stat]=0;record[stat].i=-1;myqueue.push(stat);while(!myqueue.empty()){stat=myqueue.front();myqueue.pop();for(i=0;i<SIZE*SIZE;++i){nextstat=stat^flip[i];if(flag[nextstat]==true)continue;flag[nextstat]=true;step[nextstat]=step[stat]+1;record[nextstat].prior=stat;record[nextstat].i=i;if (nextstat==0x0000){cout<<step[nextstat]<<endl;tmp1=nextstat;answer[0]=0;for (j=0;j<step[nextstat]-1;j++){tmp1=record[tmp1].prior;answer[j+1]=tmp1;}for (j=step[nextstat]-1;j>=0;j--){cout<<((record[answer[j]].i)/4)+1 <<" "<<((record[answer[j]].i)%4)+1<<endl;}return 0;}myqueue.push(nextstat);}}return 0;}
- 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 枚举
- POJ-2965-The Pilots Brothers' refrigerator
- 使用IrisSkin2.dll改变winform窗体的皮肤
- linux常用命令——awk
- 项目采购管理中的合同计算
- realoj 125 模拟windos操作系统 文件搜索
- ios文件目录管理相关类方法
- POJ 2965:The Pilots Brothers' refrigerator
- ASP.NET MVC 4 框架揭秘第十章疑问
- 自定义 Android 对话框 (AlertDialog) 的样式
- Linux驱动头文件说明
- android的Task管理
- 解读 JPG图片结构
- 今天开始写我的第一篇博客
- POJ3461《Outplo》方法:KMP
- Visual Studio 2008 中使用插件实现Extjs提示的方法