Dungeon Master
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 21230 |
|
Accepted: 8261 |
Description
You is trapped in a 3D dungeon and need to find the quickest-on-the-do out! The dungeon is composed of a unit cubes which may or may isn't being 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 are surrounded by solid rock in all sides.
is an escape possible? If Yes, how long would it take?
Input
The input consists of a number of dungeons. Each of the dungeon description starts with a line containing three integers L, R and C (all limited to the size).
L is the number of levels making up the dungeon.
R and C is the number of rows and columns making up the plan of each level.
Then there'll follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock was indicated by a ' # ' and empty cells were 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
escaped in x minute (s).
where x is replaced by the shortest time it takes to escape.
If it isn't possible to escape, print the line
trapped!
Sample Input
3 4 5s.....###. ##.. ###.#############.####...###########.###### #E1 3 3s## #E # # #0 0 0
Sample Output
Escaped in minute (s). trapped!
Source
ULM Local 1997
[Submit] [Go back] [Status] [Discuss]
#include <stdio.h>#include<string.h>#include<queue>#include<iostream>#include<algorithm>using namespacestd;BOOLvis[ -][ -][ -];Charstr[ -][ -][ -];intStep;intnex[6][3]={0,0,1,0,0,-1,1,0,0,-1,0,0,0,1,0,0,-1,0};structnode{intx, Y, Z intDis;}; Node u,v; intx, y, zintBFs () {//printf ("--->%d%d%d\n", u.x,u.y,u.z);Queue<node>Q; Q.push (U); VIS[U.Z][U.X][U.Y]=true; while(!Q.empty ()) {u=Q.front (); Q.pop (); if(str[u.z][u.x][u.y]=='E') returnU.dis; for(intI=0;i<6; i++) {v.x=u.x+nex[i][1]; V.y=u.y+nex[i][2]; V.z=u.z+nex[i][0]; if(str[v.z][v.x][v.y]!='#'&&!vis[v.z][v.x][v.y]&&v.x>=0&&v.x<x&&v.y>=0&&v.y<y&&v.z>=0&&v.z<z) {VIS[V.Z][V.X][V.Y]=true; V.dis=u.dis+1; Q.push (v); } } } return 0;}intMain () { while(SCANF ("%d%d%d", &z,&x,&y)! =EOF) { if(x==0&&y==0&&z==0) Break; memset (str,0,sizeof(str)); memset (Vis,false,sizeof(VIS)); for(intk=0; k<z;k++){ for(intI=0; i<x;i++) {scanf ("%s", Str[k][i]); for(intj=0; j<y;j++){ if(str[k][i][j]=='S') u.x=i,u.y=j,u.z=k,u.dis=0; }}} step=0; Step=BFS (); if(step>0) printf ("escaped in%d minute (s). \ n", step); Elseprintf ("trapped!\n"); } return 0;}
POJ 2251 Dungeon Master 3-dimensional BFS (water and water)