码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2251 -- Dungeon Master

时间:2014-08-02 12:12:43      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   strong   io   

Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16468   Accepted: 6395

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? 

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.

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

Sample Input

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

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

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

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

0 0 0

Sample Output

Escaped in 11 minute(s).
Trapped!

bubuko.com,布布扣
 1 /*======================================================================
 2  *           Author :   kevin
 3  *         Filename :   DungeonMaster.cpp
 4  *       Creat time :   2014-08-02 09:40
 5  *      Description :
 6 ========================================================================*/
 7 #include <iostream>
 8 #include <cstdio>
 9 #include <cstring>
10 #include <queue>
11 using namespace std;
12 struct Node
13 {
14     int x,y,z;
15     char c;
16 };
17 int cnt[31][31][31],vis[31][31][31],xx,yy,zz;
18 int cc[6][3]={{-1,0,0},{1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
19 char s[31][31][31];
20 void BFS(int a,int b,int c)
21 {
22     queue<Node>que;
23     Node node,ch,sh;
24     int q,w,e;
25     node.c=s[a][b][c];
26     node.x=a;node.y=b;node.z=c;
27     que.push(node);
28     while(!que.empty()){
29         ch=que.front();
30         if(ch.c==E)
31           break;
32         que.pop();
33         for(int i=0;i<6;i++){
34             q=ch.x+cc[i][0];
35             w=ch.y+cc[i][1];
36             e=ch.z+cc[i][2];
37             if(!vis[q][w][e] && q>=0&&q<xx && w>=0&&w<yy &&
38                         e>=0&&e<zz){
39                 cnt[q][w][e]=cnt[ch.x][ch.y][ch.z]+1;
40                 sh.c=s[q][w][e];
41                 sh.x=q;sh.y=w;sh.z=e;
42                 que.push(sh);
43                 vis[q][w][e]=1;
44             }
45         }
46     }
47 }
48 int main()
49 {
50     int as,bs,cs,ae,be,ce;
51     while(scanf("%d%d%d",&xx,&yy,&zz)!=EOF && xx+yy+zz){
52         memset(s,0,sizeof(s));
53         memset(vis,0,sizeof(vis));
54         memset(cnt,0,sizeof(cnt));
55         for(int i=0;i<xx;i++){
56             for(int j=0;j<yy;j++){
57                 getchar();
58                 for(int k=0;k<zz;k++){
59                     scanf("%c",&s[i][j][k]);
60                     if(s[i][j][k]==S){
61                         as=i;bs=j;cs=k;
62                     }
63                     if(s[i][j][k]==E){
64                         ae=i;be=j;ce=k;
65                     }
66                     if(s[i][j][k]==#){
67                         vis[i][j][k]=1;
68                     }
69                 }
70             }
71             getchar();
72         }
73         vis[as][bs][cs]=1;
74         BFS(as,bs,cs);
75         if(cnt[ae][be][ce]==0){
76             printf("Trapped!\n");
77         }
78         else printf("Escaped in %d minute(s).\n",cnt[ae][be][ce]);
79     }
80     return 0;
81 }
View Code

 

poj 2251 -- Dungeon Master,布布扣,bubuko.com

poj 2251 -- Dungeon Master

标签:des   style   blog   http   color   os   strong   io   

原文地址:http://www.cnblogs.com/ubuntu-kevin/p/3886542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!