poj-2251-Dungeon Master【BFS】
来源:互联网 发布:网络虚拟手机号申请 编辑:程序博客网 时间:2024/06/01 09:10
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 26621 Accepted: 10384
Description
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.
Is an escape possible? If yes, how long will it take?
Is an escape possible? If yes, how long will it take?
Input
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.
Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
Sample Input
3 4 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0
Sample Output
Escaped in 11 minute(s).Trapped!
#include<cstdio>#include<algorithm>#include<cstring>#include<queue>using namespace std;char map[50][50][50];int dx[6]={1,-1,0,0,0,0};int dy[6]={0,0,1,-1,0,0};int dz[6]={0,0,0,0,1,-1};int L,R,C,ans;struct node{int x,y,z,time;};int BFS(node st){node next;queue<node> qu;map[st.x][st.y][st.z]='#';qu.push(st);while(!qu.empty()){st=qu.front();qu.pop();for(int i=0;i<6;i++){next=st;next.x+=dx[i];next.y+=dy[i];next.z+=dz[i];next.time=st.time+1;if(next.x<0||next.y<0||next.z<0||next.x>=L||next.y>=R||next.z>=C||map[next.x][next.y][next.z]=='#'){continue;}if(map[next.x][next.y][next.z]=='E'){return next.time;}map[next.x][next.y][next.z]='#';qu.push(next);}}return -1;}int main(){while(scanf("%d %d %d",&L,&R,&C)&&(L||R||C)){node start;for(int i=0;i<L;i++){for(int j=0;j<R;j++){scanf("%s",&map[i][j]);for(int k=0;k<C;k++){if(map[i][j][k]=='S'){start.x=i;start.y=j;start.z=k;start.time=0;}}}}ans=BFS(start); if(ans==-1) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n",ans); }return 0;}
0 0
- 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】
- 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 2251Dungeon Master(BFS)
- linux用户登录时无法默认进入bash的解决办法
- JAVA WEB项目中,配置一个代替404错误页面
- 5-26 单词长度 (15分)
- jQuery ajax - getScript() 方法和getJSON方法
- hdu 2516 取石子游戏 (FIB博弈)
- poj-2251-Dungeon Master【BFS】
- 12个免费的 Twitter Bootstrap 后台模板
- Android开发之调用相机拍照和调用系统相册
- 针对本科和硕士应届生的算法面试题
- linux进程总结
- Android逆向修改工具简单讲解-Androidkiller-Reflector
- mysql索引的最左前缀原则
- 微信支付—关于sgin签名的坑
- Cpp环境【NOIP practice】【BSOJ1878】【Vijos1172】 山头狙击战