poj 1753 Flip Game 二进制状态压缩
来源:互联网 发布:淘宝网店标志图片 编辑:程序博客网 时间:2024/06/05 01:58
poj 1753 Flip Game
http://poj.org/problem?id=1753
#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;int bit[18],vis[70000] , value;int mov[5][2]={0, 0, -1, 0, 1, 0, 0, 1, 0, -1};char map[5][5];struct node{ int v , step;};void init(){ int i, j; value=0 ; memset(vis, 0, sizeof(vis)); for(i=0 ;i< 4; i++){ for(j=0; j<4; j++){ if(map[i][j]=='b') value|=bit[i*4+j]; } }//cout<<"AA"<<value<<endl; vis[value]=1;}void bfs(){ queue <node > q; int i , j; node head, start, next ; head.v = value; head.step = 0; q.push(head); while(!q.empty()){ int tx, ty, x, y; head=q.front() ; // printf("%d %d \n", head.v, head.step); q.pop(); if(head.v ==0||head.v ==(0xffff)) {printf("%d\n",head.step);return ;} next.step = head.step + 1; for(i=0 ;i< 16; i++){ x=i/4; y=i%4; next.v= head.v ; for(j =0; j<5; j++){ tx=x+mov[j][0]; ty=y+mov[j][1]; if(tx<0 || tx>=4 || ty<0 || ty>=4 ) continue; next.v ^=bit[tx*4 + ty]; } if(next.v ==0||next.v ==(0xffff)) {printf("%d\n",next.step);return ;} if(!vis[next.v]) { vis[next.v]=1; q.push(next); } } } printf("Impossible\n");}int main(){ // freopen("1.txt", "r", stdin); int i, j; for(i=0; i<16; i++){ bit[i]= 1<<i ;//cout<<bit[i]<<" "; } while(scanf("%s%s%s%s",map[0], map[1], map[2], map[3] )!=EOF){ init(); bfs(); } return 0;}
- poj 1753 Flip Game 二进制状态压缩
- POJ 1753 Flip Game 状态压缩 枚举
- Poj 1753 Flip Game 状态压缩 + DFS
- POJ 1753 Flip Game(状态压缩)
- 【BFS+状态压缩】-POJ-1753-Flip Game
- POJ 1753 Flip Game(状态压缩BFS)
- POJ 1753 Flip Game(BFS+状态压缩)
- poj 1753 Flip Game 状态压缩
- poj 1753 Flip Game(状态压缩枚举)
- POJ 1753 Flip Game BFS+位压缩状态
- zoj 2050 || poj 1753 Flip Game(状态压缩 简单BFS)
- POJ 1753 Flip Game (黑白棋) (状态压缩+BFS)
- 20140426 【DP - 状态压缩】 POJ 1753 Flip Game
- POJ 1753 Flip Game (状态压缩+BFS) -- 解题报告
- POJ 1753 Flip Game(bfs+状态压缩+位运算)
- Flip Game (poj 1753)枚举+二进制
- POJ 1753Flip Game(二进制暴力)
- POJ:1753-Flip Game(二进制+bfs)
- 第十二周实验报告2
- ICESSL使用备忘
- 程序员面试题精选100题(15)-含有指针成员的类的拷贝[C/C++/C#]
- 今天的工作增强
- notification相关二
- poj 1753 Flip Game 二进制状态压缩
- 用WinInet API实现ftp文件上传
- 线性表基础知识(四)
- 3D 学习笔记 几何混合 Geometry Blending
- 黑马程序员_分支结构与循环结构以及跳转语句
- Doubly connected edge list
- centos6.2使用yum安装lamp
- 开始找工作了。。。
- va_list va_start va_arg va_end 详解