poj2251 Dungeon Master 简单BFS
来源:互联网 发布:nba全明星赛数据 编辑:程序博客网 时间:2024/04/30 07:01
题目链接:http://poj.org/problem?id=2251
题意: 从S走到E,若走通,输出Escaped in X minute(s).若走不出,输出"Trapped!"
方法:简单BFS;
#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;char dun[40][40][40];bool vis[40][40][40];int L,R,C,fx[6][3]={{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};struct node{int l,r,c,tim;}ic,tmp,s,e;void bfs(){memset(vis,0,sizeof(vis));queue<node>q;q.push(s);vis[s.l][s.r][s.c]=1;while(!q.empty()){ic=q.front();q.pop();if(ic.l==e.l&&ic.r==e.r&&ic.c==e.c){e.tim=ic.tim;return ;} for(int i=0;i<6;++i){int l,r,c;l=ic.l+fx[i][0];r=ic.r+fx[i][1];c=ic.c+fx[i][2];if(l<0||r<0||c<0||l>=L||r>=R||c>=C)continue;if(vis[l][r][c]||dun[l][r][c]=='#')continue;vis[l][r][c]=1;tmp.l=l;tmp.r=r;tmp.c=c;tmp.tim=ic.tim+1;q.push(tmp);}}}int main(){while(scanf("%d%d%d",&L,&R,&C)&&(L||R||C)){for(int i=0;i<L;++i) for(int j=0;j<R;++j) for(int k=0;k<C;++k) { cin>>dun[i][j][k]; if(dun[i][j][k]=='S') { s.l=i; s.r=j; s.c=k; s.tim=0;}if(dun[i][j][k]=='E'){e.l=i;e.r=j;e.c=k;e.tim=0;}}bfs();if(!e.tim)cout<<"Trapped!"<<endl;else cout<<"Escaped in "<<e.tim<<" minute(s)."<<endl;}}
0 0
- poj2251 Dungeon Master 简单BFS
- poj2251-Dungeon Master(简单bfs)
- poj2251 Dungeon Master (BFS)
- Dungeon Master(poj2251,bfs)
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master bfs
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master(BFS)
- POJ2251 Dungeon Master BFS
- [bfs]poj2251 Dungeon Master
- poj2251 dungeon master【BFS】~
- POJ2251 Dungeon Master(bfs)
- POJ2251 Dungeon Master(BFS)
- POJ2251-Dungeon Master-BFS
- 【POJ2251】Dungeon Master(bfs)
- poj2251-bfs- Dungeon Master
- POJ2251 Dungeon Master 【BFS】
- POJ2251:Dungeon Master(BFS)
- Delphi 常用API函数 存档
- android:ems=“10”的意思
- 面试题57:删除链表中的重复节点
- 移动端设计规范
- 32位保护模式学习小结(1)
- poj2251 Dungeon Master 简单BFS
- 2116数据结构实验之链表一:顺序建立链表
- Spring4笔记----工厂方法配置bean
- C# Matlab 相互调用
- Git 进阶 —— 远程仓库
- 1091. Acute Stroke (30)
- java语言基础入门——字符串两种建立方式的比较
- HDU 4864 Task
- Faster R-CNN系列之PYTHON篇