poj 2965 水 = =
来源:互联网 发布:mac虚拟机蓝屏 编辑:程序博客网 时间:2024/05/16 11:07
题目链接:http://poj.org/problem?id=2965
题意:4*4的地图,反转某一点的话他所在的行和列均反转,问翻转到全部为-的时候最少几步
思路:有种精妙的解法,没看= =,第一反应就是压缩后进行bfs,不难,但是实现的时候。。是太久没写搜索了么。。标题的含义就是我很水。。。
#include<cstdio>#include<iostream>#include<cstring>using namespace std;const int maxn = (1<<16) + 10;int fa[maxn];int t[maxn];int nn[maxn];int way[maxn];int num[20];int vis[maxn];int bfs(int s){ int i = 0,now=0;//i当前存到数组那一位,now bfs到那一位 fa[0]=-1; t[0]=0; nn[0]=s; while(1){ if(!nn[now])break; for(int k = 0;k < 16; k ++){ if(vis[nn[now]^num[k]])continue; i++; fa[i]=now; t[i] = t[now]+1; nn[i] = nn[now]^num[k]; vis[nn[now]^num[k]]=1; way[i] = k; if(nn[i]==0){now = i-1;break;} } now++; } cout<<t[now]<<endl; for(int i=now;i;i=fa[i]){ cout<<way[i]/4+1<<' '<<way[i]%4+1<<endl; }}void make(int now){ int a[4][4]={0}; for(int i=0;i<4;i++){ a[i][now%4]=1; a[now/4][i]=1; } for(int i=0;i<4;i++) for(int j=0;j<4;j++) if(a[i][j])num[now]+=1<<(4*i+j);}void init(){ for(int i=0;i<16;i++){ make(i); }}int main(){ init(); int s=0; char c; for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ scanf("%c",&c); if(c=='+')s+=1<<(4*i+j); } getchar(); } bfs(s); return 0;}
0 0
- poj 2965 水 = =
- http://poj.org/problem?id=2965
- poj 2478http://poj.org/problem?id=2478
- poj 1273 http://poj.org/problem?id=1273
- poj 1426 http://poj.org/problem?id=1426
- POJ 1251(http://poj.org/problem?id=1251)
- POJ 2828 Buy Ticketshttp://poj.org/problem?id=2828
- poj 3624 http://poj.org/problem?id=3624
- POJ 2965
- POJ 2965
- poj-2965
- poj 2965
- poj 2965
- poj-2965
- POJ 2965
- POJ 2965
- poj.2965
- poj 2965
- pig limit 少于10行,会返回所有记录
- oracle 管道化表函数(Pipelined Table)
- ArcGIS教程:栅格表面的分辨率
- C源程序的 编译 链接 main()的调用粗程
- 继承总结
- poj 2965 水 = =
- HDU 4725 The Shortest Path in Nya Graph dijkstra优化
- 标准正态分布面积(面积=比例=概率,不仅限于正态分布)
- 提高tomcat的并发能力
- java--四则运算
- jQuery.fn的作用是什么
- Preference中比较重要的监听点击事件方法
- hadoop学习工作总结(六)之生成hive的一个存储过程
- Java中的equals()和==