Dungeon Master
来源:互联网 发布:网络教育什么时间报名 编辑:程序博客网 时间:2024/05/07 12:16
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<iostream>#include<cstdio>#include<queue>#include<cstring>using namespace std;struct node{int x,y,z,s;};int next[6][3]={{0,1,0},{0,-1,0},{1,0,0},{-1,0,0},{0,0,1},{0,0,-1}};int n,m,k,endx,endy,endz,flag;char e[35][35][35];int bfs(int a,int b,int c){struct node t1,t2,t3;queue<node> q;t1.x=a;t1.y=b;t1.z=c;t1.s=0;q.push(t1);while(!q.empty()){t2=q.front();q.pop();for(int i=0;i<6;i++){t3.x=t2.x+next[i][0];t3.y=t2.y+next[i][1];t3.z=t2.z+next[i][2]; t3.s=t2.s+1; if(t3.x<0 || t3.x>=n || t3.y<0 || t3.y>=m || t3.z<0 || t3.z>=k) continue; if(e[t3.x][t3.y][t3.z]!='#'){if(t3.x==endx && t3.y==endy && t3.z==endz){ flag=1; return t3.s;}q.push(t3);e[t3.x][t3.y][t3.z]='#'; } }}}int main(){int startx,starty,startz;while(cin >> n >> m >> k){if(n==0 && m==0 && k==0) break;for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ for(int r=0;r<k;r++){ cin >> e[i][j][r]; if(e[i][j][r]=='S'){ startx=i;starty=j;startz=r; } if(e[i][j][r]=='E'){ endx=i;endy=j;endz=r; } } } } flag=0; int sum=bfs(startx,starty,startz); if(flag==1) printf("Escaped in %d minute(s).\n",sum); else cout << "Trapped!" << endl;}return 0;}
0 0
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- JavaScript描述数据结构与算法——队列
- 共模干扰、差模干扰定义与消除
- 图的存储结构——邻接矩阵(算法简介/c++实现)
- 胡凯“Android内存优化之OOM”
- 第一类stiring数
- Dungeon Master
- 网络体系概述
- OS X 10.11下PHPstorm php-cgi not found 并且访问项目目录502
- java的调试技巧
- hdoj In Action 3339 (dijiks++01背包) 好题
- setClickable(true)不起作用
- Linux硬连接和软连接的区别
- 图像处理与计算机视觉:基础,经典以及最近发展(3)计算机视觉中的信号处理与模式识别
- 设计记录江湖仇家的小本本