poj 2251 三维BFS 无坑点
来源:互联网 发布:stata软件和spss 编辑:程序博客网 时间:2024/06/07 01:55
#include<iostream>#include<cstring>#include<cstdio>#include<queue>using namespace std;char map[35][35][35];bool vis[35][35][35];int t,r,c;int dirx[6]={ 1,-1, 0, 0, 0, 0}; #多加两个dirint diry[6]={ 0, 0, 1,-1, 0, 0};int dirz[6]={ 0, 0, 0, 0, 1,-1};struct loc{int x,y,z;int step;};int main(){while(scanf("%d%d%d",&t,&r,&c)==3){if(t==0 && r==0 && c==0) break;int sx,sy,sz;memset(map,0,sizeof(map));memset(vis,0,sizeof(vis));for(int i=1;i<=t;i++){for(int j=1;j<=r;j++){for(int k=1;k<=c;k++){cin >> map[i][j][k];if(map[i][j][k]=='S'){sx=i;sy=j;sz=k;}}}}//cout << 1 << endl;queue<loc> q;loc point;point.x=sx;point.y=sy;point.z=sz;point.step=0;//cout << "*"<< point.x <<","<<point.y<<","<<point.z<<endl;q.push(point);int ans=0;while(!q.empty()){if(ans) break;loc tmp=q.front();q.pop();for(int i=0;i<6;i++){loc nextstep=tmp;nextstep.x+=dirx[i];nextstep.y+=diry[i];nextstep.z+=dirz[i];//cout << nextstep.x <<','<<nextstep.y<<','<<nextstep.z<<endl;if(vis[nextstep.x][nextstep.y][nextstep.z]) continue;if(nextstep.x<1 || nextstep.x>t) continue;if(nextstep.y<1 || nextstep.y>r) continue;if(nextstep.z<1 || nextstep.z>c) continue;if(map[nextstep.x][nextstep.y][nextstep.z]=='#') continue;if(map[nextstep.x][nextstep.y][nextstep.z]=='E'){ans=nextstep.step+1;break;}vis[nextstep.x][nextstep.y][nextstep.z]=1;if(ans) break;nextstep.step++;q.push(nextstep);}}if(ans){printf("Escaped in %d minute(s).\n",ans);}else {printf("Trapped!\n");}}}
阅读全文
0 0
- poj 2251 三维BFS 无坑点
- poj 2251 三维BFS
- POJ-2251三维bfs
- POJ 2251 (三维迷宫问题) DFS /BFS
- POJ 2251 Dungeon Master (三维BFS)
- POJ 2251:Dungeon Master(三维BFS)
- POJ 2251 Dungeon Master (三维迷宫 BFS)
- POJ 2251 Dungeon Master(三维BFS)
- poj 2251 Dungeon Master 三维bfs
- poj 2251 Dungeon Master(三维BFS)(中等)
- poj 2251 Dungeon Master(BFS三维)
- POJ 2251 Dungeon Master(三维bfs)
- POJ 2251 Dungeon Master(三维bfs)
- <三维BFS搜索> POJ 2251 Dungeon Master
- POJ 2251:Dungeon Master(三维BFS)
- POJ 2251 Dungeon Master(三维BFS)
- POJ 2251 (BFS 简单三维迷宫)
- POJ 2251 Dungeon Master 三维BFS
- 3自定义View系列课程学习笔记——之Measure测量
- Java--常用源码--排序算法
- 文件写入、读取的指针问题
- Windows 环境下使用 GCC
- Android程序中View的四种点击事件
- poj 2251 三维BFS 无坑点
- PAT 甲级 1024. Palindromic Number(大整数相加的回文数字)
- C语言中strcpy,strcmp,strlen,strcat函数原型
- io流处理复制文件的问题
- JAVA 两个大字符串数字相加
- va_list / vfprintf / va_arg & printf(const char *format,...)
- STDOUT_FILENO和stdin的区别
- 四、递归递推
- poj 3984 迷宫问题 BFS+路径记录