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. JavaScript基础进阶之常用字符串方法总结

    前面三篇文章简单的把JavaScript基础内容过了一遍,我们已经可以用JavaScript写一些简单的代码了. 今天主要总结一下JavaScript中String对象中自带的一些方法,来帮助我们处理 ...

  2. Django之模板配置(template)

    Django模板系统 官方文档 jinja2模块中文 jinja2模块官方 常用语法 只需要记两种特殊符号: {{  }}和 {% %} 变量相关的用{{}},逻辑相关的用{%%}. 变量 在Djan ...

  3. Latex排版全解

    Latex排版全解 LATEX(英语发音:/ˈleɪtɛk/ LAY-tek或英语发音:/ˈlɑːtɛk/ LAH-tek,音译“拉泰赫”),是一种基于TEX的排版系统,由美国电脑学家莱斯利•兰伯特在 ...

  4. configuration on ubuntu server

    1.network configuration 1.1 static ip sudo vi /etc/network/interfaces auto eth0 iface eth0 inet stat ...

  5. BZ4326 运输计划

    Time Limit: 30 Sec Memory Limit: 128 MB Submit: 2132 Solved: 1372 Description 公元 2044 年,人类进入了宇宙纪元.L ...

  6. C++的四种显示类型转换

    static_cast 除了含有底层const的类型转换,其他的一般都可以用这个static_cast const_cast 专门用来转换底层const,将常量转换为非常量,但是假如这个量如果本身是常 ...

  7. MySQL——总结

    数据库命令:创建create database 数据库名 charset=utf8;删除drop database 数据库名;查看所有数据库:show databases;使用数据库:use 数据库名 ...

  8. Longest Substring Without Repeating Characters[medium]

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  9. C中typedef 函数指针的使用

    类型定义的语法可以归结为一句话:只要在变量定义前面加上typedef,就成了类型定义.这儿的原本应该是变量的东西,就成为了类型. int integer;     //整型变量int *pointer ...

  10. koa2实现简单的图片上传

    1.安装koa-body 2.引入koa-body const koa = require('koa'); const fs = require('fs'); const koaBody = requ ...