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. CORS跨域模型浅析及常见理解误区分析

    CORS跨域资源共享是前后端跨域十分常用的一种方案,主要依赖Access-Control-Allow(ACA)系列header来实现一种协商性的跨域交互. 基本模型 其中的具体流程大致可以分为以下几步 ...

  2. SICP 习题 (1.34)解题总结

    SICP 习题 1.34的题目比較特别一点.对于没有接触过高阶函数的同学们来说是个非常好的学习机会. 题目是这种,假设我们定义以下的过程: (define (f g)   (g 2)) 那么就有: ( ...

  3. 关于vmware workstation10常见问题

    简单的说明:win7和win10的解决办法都是这个,都可以用这个解决. 这是一个共性的问题. 出现这个问题的原因是: a.要么是系统更新没有及时正确的关闭虚拟机导致的; b.没有及时将虚拟机手动关闭再 ...

  4. Service通信

    1.简介 Service通信是双向的, 它不仅可以发送消息, 同时还会有反馈. 所以service包括两部分, 一部分是请求方( Clinet) , 另一部分是应答方/服务提供方( Server) . ...

  5. [NOI2001]炮兵阵地 【状压DP】

    #\(\color{red}{\mathcal{Description}}\) \(Link\) 司令部的将军们打算在\(N \times M\)的网格地图上部署他们的炮兵部队.一个\(N \time ...

  6. java 快速开发框架平台 二次开发 代码生成器 springmvc SSM后台框架源码

    官网 http://www.fhadmin.org/D 集成安全权限框架shiro  Shiro 是一个用 Java 语言实现的框架,通过一个简单易用的 API 提供身份验证和授权,更安全,更可靠E ...

  7. iOS之让UISearchBar搜索图标和placeholder靠左显示

    系统UISearchBar效果图: 需求效果图: 两种方案: 找到UISearchBar上的放大镜图标, 修改Frame. 同时判断在有无文本内容更改placeholder的颜色. 利用UISearc ...

  8. JS基础-组成

    类型 前缀 类型 实例 数组 a Array aItems 布尔值 b Boolean bIsComplete 浮点数 f Float fPrice 函数 fn Function fnHandler ...

  9. laravel 的用户认证

    1.简介 Laravel 中实现用户认证非常简单.实际上,几乎所有东西都已经为你配置好了.配置文件位于config/auth.php,其中包含了用于调整认证服务行为的.文档友好的选项配置. 在底层代码 ...

  10. VIM - visual selection 模式下的简单操作

    1. 概述 vim 的 visual selection 模式下的简单操作 2. visual selection 模式 概述 可视化选择 可视化选择 vim 的一种专门用来选择的模式 可以提供相对于 ...