POJ-2965-The Pilots Brothers' refrigerator-bfs枚举-位运算
来源:互联网 发布:第三波软件 编辑:程序博客网 时间:2024/05/18 10:51
http://poj.org/problem?id=2965
规模比较小,每一个步骤都用位运算就好了
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <map>#include <set>#include <vector>#include <iostream>using namespace std; char mp[5][5];int tm[5][5];struct node{int x,num,last;node(){}node(int a,int b,int c){x=a;num=b;last=c;}}; node ans[1000000] ;int prin[100000][2];int ok_p;int ok;int wei[16]={63624,62532,61986,61713,36744,20292,12066,7953,35064,17652,8946,4593,34959,17487,8751,4383};int vis[1<<16+5];void get_ans(int xx){if (xx==1)return ; prin[++ok_p][0]=ans[xx].num/4;prin[ok_p][1]=ans[xx].num%4;get_ans(ans[xx].last); } node que[500100];int que_ed,que_st ;int main(){que_st= que_ed=0;ok=0;ok_p=0;scanf("%s",mp[0]); scanf("%s",mp[1]);scanf("%s",mp[2]);scanf("%s",mp[3]);int tmp=0;int i,j;for (i=3;i>=0;i--){for (j=3;j>=0;j--){tmp<<=1;if (mp[i][j]=='+') // + 0 - 0tmp++;}} if (!tmp){printf("0\n");return 0;}que[++que_ed]=node(tmp,0,1);//sb.push(node(tmp,0,1)); while(que_ed>que_st){ node rt=que[++que_st];//sb.pop(); ans[++ok]=rt;int tmp=rt.x; int i=0,j=0;int k,h,p; int flag=0;for ( k=0;k<16;k++){ int tt=rt.x^wei[15-k]; if (vis[tt]) continue;vis[tt]=1;node ss(tt,k,ok); //sb.push(ss); que[++que_ed]=ss;if (ss.x==0){prin[++ok_p][0]=k/4;prin[ok_p][1]=k%4;get_ans(ok); flag=1;break;} } if (flag)break;} printf("%d\n",ok_p);for (i=ok_p;i>=1;i--){printf("%d %d\n",prin[i][0]+1,prin[i][1]+1);} return 0;}
0 0
- POJ-2965-The Pilots Brothers' refrigerator-bfs枚举-位运算
- POJ 2965 The Pilots Brothers' refrigerator BFS+位运算
- POJ 2965 The Pilots Brothers' refrigerator(枚举+位运算)
- poj-2965-The Pilots Brothers' refrigerator(巧妙的位运算)
- POJ 2965-The Pilots Brothers' refrigerator(位运算+BFS+回溯路径)
- 【BFS|位运算+输出路径】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【枚举】
- The Pilots Brothers' refrigerator 枚举 Poj 2965
- poj_2965 The Pilots Brothers' refrigerator(bfs+位运算)
- poj2965 The Pilots Brothers' refrigerator(位运算)
- POJ 2965 The Pilots Brothers' refrigerator(BFS+二进制判重)
- BFS + 状态压缩 POJ 2965 The Pilots Brothers' refrigerator
- [leetcode] 173. Binary Search Tree Iterator 解题报告
- /bin/bash^M: bad interpreter: No such file or dire
- 自己动手用C++写的图像处理软件(不调用外部包)
- [看书日记20160112]Binder
- 使用ImageLoader第三方框架,加载网络图片
- POJ-2965-The Pilots Brothers' refrigerator-bfs枚举-位运算
- leetcode之 Lowest Common Ancestor of a Binary Tree
- nginx+tomcat集群
- QTGraphicsViewFramework学习
- cf-edu#5-C The Labyrinth-dfs记忆化搜搜
- 深入了解JAVA可变长度的参数(Varargs)
- Android中 Window 、WindowManager、WindowManager.LayoutParams 相关内容
- Cocos2dX笔记1——生成Docs
- cf-edu#5-D - Longest k-Good Segment-map+贪心维护