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!
//题意:
//相当于一栋大楼里面很多秘密通道,
//S是起始位置,E是终点位置,
//‘#’是墙,‘.’是路,问从S出发最少经过多长时间就到达E处;
//
//分析:
//和迷宫不同的是,迷宫是平面上东南西北的移动,
//相当于在大楼里面的一层楼里找出口,而这个题目在迷宫的基础上又增加了上下的移动,
//即大楼里面的上下层之间的移动,
//所以需要建立三维的数组,找到S的位置,
//移动方向由4个增加到6个,直到找到E为止,如果找遍了所有的能走的地方都没找到出口E,就出不来了!!!
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int zz, xx, yy, tx, ty, tz;
int start_x, start_y, start_z, end_x, end_y, end_z;
char ch;
int map[][][];
int book[][][]; int d[][] ={-,,,,,,,-,,,,,,,,,,-}; struct node{
int x,y,z;
int step;
}q; void BFS(){
q.x = start_x,q.y = start_y,q.z = start_z;
q.step = ;
queue<node>qq;
qq.push(q);
book[start_x][start_y][start_z] = ;
while(!qq.empty()){
node t = qq.front();
qq.pop(); // cout<<" x y z ="<<t.x<<" "<<t.y<<" "<<t.z<<endl;
if(t.x==end_x && t.y==end_y && t.z == end_z){
cout<<"Escaped in "<<t.step<<" minute(s)."<<endl;
return;
}
for( int i = ; i < ; i++ ) { tz = t.z + d[i][];
tx = t.x + d[i][];
ty = t.y + d[i][];
if( tz>zz||tz< || tx>xx||tx< || ty>yy||ty< ) continue;
if( map[tz][tx][ty] == && book[tz][tx][ty]== ){
node temp;
book[tz][tx][ty]=;
temp.z = tz, temp.x = tx, temp.y = ty;
temp.step = t.step + ;
qq.push(temp);
}
}
}
cout<<"Trapped!"<<endl;
return;
} int main() {
while(scanf("%d%d%d",&zz,&xx,&yy),zz+xx+yy)
{ for( int i = ; i <= zz; i++ ) {
for( int j = ; j <= xx; j++ ) {
for( int k = ; k <= yy; k++ ) {
cin>>ch;
switch(ch){
case 'S':start_z = i,start_x = j,start_y = k; break;
case 'E':end_z = i, end_x = j, end_y = k; break;
case '.':map[i][j][k] = ;break;
case '#':map[i][j][k] = ;break;
}
}
}
}
memset(book,,sizeof(book));
BFS();
}
return ;
}

POJ2251-Dungeon Master(3维BFS)的更多相关文章

  1. poj 2251 Dungeon Master 3维bfs(水水)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21230   Accepted: 8261 D ...

  2. POJ2251——Dungeon Master(三维BFS)

    和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...

  3. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  4. POJ - 2251 Dungeon Master 多维多方向BFS

    Dungeon Master You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is ...

  5. BFS POJ2251 Dungeon Master

    B - Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  6. POJ2251 Dungeon Master —— BFS

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  7. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

  8. POJ-2251 Dungeon Master (BFS模板题)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  9. POJ2251 Dungeon Master(bfs)

    题目链接. 题目大意: 三维迷宫,搜索从s到e的最小步骤数. 分析: #include <iostream> #include <cstdio> #include <cs ...

  10. Dungeon Master(三维bfs)

    题目链接:http://poj.org/problem?id=2251 题目: Description You are trapped in a 3D dungeon and need to find ...

随机推荐

  1. BZOJ 3171 循环格 最小费用流

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3171 题目大意: 一个循环格就是一个矩阵,其中所有元素为箭头,指向相邻四个格子.每个元 ...

  2. 4-3 R语言函数 mapply

    #mapply(函数/函数名,数据,函数相关的函数) > list(rep(1,4),rep(2,3),rep(3,2),rep(4,1)) [[1]] [1] 1 1 1 1 [[2]] [1 ...

  3. sort与sorted

    Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列. 1.list.sort()方法仅被定义在list中,相反地so ...

  4. 集合之Stack

    在Java中Stack类表示后进先出(LIFO)的对象堆栈.栈是一种非常常见的数据结构,它采用典型的先进后出的操作方式完成的.每一个栈都包含一个栈顶,每次出栈是将栈顶的数据取出,如下: Stack通过 ...

  5. codewars-7kyu:Sum of the first nth term of Series

    Task: Your task is to write a function which returns the sum of following series upto nth term(param ...

  6. CS231N assignment1

    # Visualize some examples from the dataset. # We show a few examples of training images from each cl ...

  7. 使用XWAF框架(2)——上传文件

    XWAF提供了上传文件的HttpFileUploader工具类,具备强大的多文件上传.文件类型过滤.文件大小限制.存储目录设置.文件名称更改等功能,简化了Web应用开发的编程工作. 它能同时解析表单参 ...

  8. 虹软人脸识别iOS SDK2.0

    最近公司要在APP上添加一个人脸识别功能,在网上搜了一圈,发现虹软的人脸识别SDK挺好用的,而且还免费,所以就下载了他们的SDK研究了一下.总的来看功能挺好用的,只是demo上面部分功能不是很完善,所 ...

  9. localStorage 和 sessionStorage

    1.概述 以前本地存储使用 cookie.但是 Web 存储需要更加安全和快速.所以就出现了localStorage 和 sessionStorage. 2.sessionStorage,localS ...

  10. 大数据入门第七天——MapReduce详解(一)入门与简单示例

    一.概述 1.map-reduce是什么 Hadoop MapReduce is a software framework for easily writing applications which ...