POJ 2965 The Pilots Brothers' refrigerator(BFS+二进制判重)
来源:互联网 发布:学生赚钱的软件 编辑:程序博客网 时间:2024/05/21 11:55
很奇怪,提交时候用C++就超时而G++则不会.
875MS过的
#include <iostream>#include <cstdio>#include <queue>#include <map>const int maxn=65538;using namespace std;struct state{int data;int cp;};bool vis[maxn];state q[maxn];int fa[maxn];void printPath(int v,int cnt){if(fa[v]==0){printf("%d\n",cnt);return;}printPath(fa[v],cnt+1);printf("%d %d\n",q[v].cp/4+1,q[v].cp%4+1);}void bfs(state s){int front=1,rear=1;q[rear++]=s;vis[s.data]=1;while (front<rear){state t=q[front];if(t.data==0){printPath(front,0);return;}for (int i=0;i<16;++i){state temp=t;for (int j=i%4;j<16;j+=4){temp.data=temp.data^(1<<j);}for (int j=i&0xFFFC,bound=j+4;j<bound;++j){if(j==i)continue;temp.data=temp.data^(1<<j);}if(!vis[temp.data]){fa[rear]=front;temp.cp=i;vis[temp.data]=1;q[rear++]=temp;}}front++;}}int main(){state start;start.data=start.cp=0;for (int i=0;i<16;++i){char v;cin>>v;if(v=='+'){start.data|=(1<<i);}}bfs(start);return 0;}
- POJ 2965 The Pilots Brothers' refrigerator(BFS+二进制判重)
- POJ:2965 The Pilots Brothers' refrigerator(二进制枚举)
- POJ 2965 The Pilots Brothers' refrigerator BFS+位运算
- BFS + 状态压缩 POJ 2965 The Pilots Brothers' refrigerator
- POJ 2965The Pilots Brothers' refrigerator (bfs)
- POJ-2965-The Pilots Brothers' refrigerator-bfs枚举-位运算
- POJ 2965 The Pilots Brothers' refrigerator【BFS+状压 Or 脑洞】
- poj 2965 The Pilots Brothers' refrigerator (状压+bfs)
- 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
- MATLAB学笔记_帮助查询
- PHPCMS2008的导航位置修改
- Lucene学习笔记【2013-04-12更新】
- 国际C语言混乱代码大赛优胜作品详解之“A clock in one line”
- js控制多选框左右移动
- POJ 2965 The Pilots Brothers' refrigerator(BFS+二进制判重)
- 数据结构基础_插入字符串
- js控制多选框上下移动
- NUMBER Data Type
- 常见的目标检测中的背景建模方法漫谈
- 客户端验证总结
- backbone 重量级Web的MVC开发框架
- 你用或者不用:线程中synchronized关键字使用总结
- 高手的Blog 及ACM 好的网站