Dungeon Master
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 19222 |
|
Accepted: 7466 |
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!
#include <stdio.h> #include <string.h> #include <queue> #define MAX 288using namespace Std;int l,r,c; Char map[max][max][max];struct node{int x,y,z;int step;}; void BFs (int x1,int y1,int z1,int x2,int y2,int z2) {int J,i,ok=0;int move[6][3]={0,0,1,0,0,-1,1,0,0,-1,0,0,0,1,0,0,-1,0 };queue<node>q;node Beg,end;beg.x=x1;beg.y=y1;beg.z=z1;beg.step=0;q.push (Beg); while (!q.empty ()) {end= Q.front (); Q.pop (); if (end.x==x2&&end.y==y2&&end.z==z2) {ok=1;break;} for (i=0;i<6;i++) {beg.x=end.x+move[i][0];beg.y=end.y+move[i][1];beg.z=end.z+move[i][2];if (0<=beg.x& &beg.x<l&&0<=beg.y&&beg.y<r&&0<=beg.z&&beg.z<c&&map [Beg.x] [BEG.Y] [beg.z]!= ' # ') {map[beg.x][beg.y][beg.z]= ' # '; Beg.step=end.step+1;q.push (Beg);}}} if (OK) printf ("escaped in%d minute (s). \ n", end.step); elseprintf ("trapped!\n");} int main () {int i,j,k,x1,y1,z1,x2,y2,z2;while (scanf ("%d%d%d", &l,&r,&c) &&l!=0&&r!=0 &&c!=0) {for (i=0;i<l;i++) {for (j=0;j<r;j++) {scanf ("%s", Map[i][j]);}} for (i=0;i<l;i++) for (j=0;j<r;j++) for (k=0;k<c;k++) {if (map[i][j][k]== ' S ') {x1=i;y1=j;z1=k;} else if (map[i][j][k]== ' E ') {x2=i,y2=j;z2=k;}} BFS (X1,Y1,Z1,X2,Y2,Z2);} return 0;}
POJ 2251 Dungeon Master