# UVA 532 Dungeon Master

You are trapped in a 3D dungeon and need to find the quickest way out!The dungeon is composedof unit cubes which may or may not be filled with rock. It takes one minuteto move one unit north,south, east, west, up or down. You cannot move diagonally and the maze issurrounded by solid rock on all sides.

Is an escape possible? If yes, how long will it take?

The input file consists of a number of dungeons. Each dungeon descriptionstarts with a linecontaining 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 describesone 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 blankline after each level. Input is terminated by three zeroes for L, R and C.

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 is not possible to escape, print the line

Trapped!

```3 4 5
S....
.###.
.##..
###.#

#####
#####
##.##
##...

#####
#####
#.###
####E

1 3 3
S##
#E#
###

0 0 0
```
```Escaped in 11 minute(s).
Trapped!
```

AC的代码如下：

``````#include

using namespace std;
struct point
{
int x1;
int y1;
int z1;
};
point q[30*30*30+5];
char graph[30][30][30];
int dist[30][30][30];
int dx[]= {0,0,0,0,1,-1};
int dy[]= {0,0,-1,1,0,0};
int dz[]= {-1,1,0,0,0,0};
int vis[30][30][30];
int L,R,C;
void bfs(int x,int y,int z)
{
int front=0,rear=0;
point a;
a.x1=x;
a.y1=y;
a.z1=z;
q[rear++]=a;
vis[x][y][z]=1;
while(front

=0newy=0newz=0newx

LRC) { char c; int x,y,z,ex,ey,ez; memset(vis,0,sizeof vis); memset(dist,0,sizeof dist); if(L==0) break; for(int i=0; i

c; if(c!=' 'c!='\n') graph[i][j][k]=c; if(c=='S') { x=i; y=j; z=k; } if(c=='E') { ex=i; ey=j; ez=k; } } bfs(x,y,z); if(dist[ex][ey][ez]!=0) cout"Escaped in "

" minute(s)."

``````
` `
• 09:18
• 01:01
• 02:01
• 01:02
• 03:00