Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 27520   Accepted: 10776

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!
————————————分割线————————————
 
广搜

 #include "iostream"
#include "cstdio"
#include "fstream"
#include "sstream"
#include "cstring" using namespace std;
const int maxN = 3e4 + 1e2 ;
struct Queue { int x , y , z ; } ;
typedef long long QAQ ; int dx[ ] = { , - , , , , } ;
int dy[ ] = { , , , , - , } ;
int dz[ ] = { , , - , , , } ; int step[ maxN ] ;
Queue Q[ maxN ] ;
bool vis[ ][ ][ ] ;
char map[ ][ ][ ] ; int L , R , C ;
int start_x , start_y , start_z , des_x , des_y , des_z ;
//QAQ Ans ; void Init ( ) {
memset ( vis , false , sizeof ( vis ) ) ;
memset ( step , , sizeof ( step ) ) ;
} inline bool Check ( const int x_x , const int y_y , const int z_z ) {return ( x_x == des_x && y_y == des_y && z_z == des_z ) ? true : false ; }
int BFS ( ) {
int Head = , Tail = ;
Q[ Tail ].x = start_x ;
Q[ Tail ].y = start_y ;
Q[ Tail ].z = start_z ;
while ( Head <= Tail ) {
for ( int i= ; i< ; ++i ) {
int xx = Q[ Head ].x + dx[ i ] ;
int yy = Q[ Head ].y + dy[ i ] ;
int zz = Q[ Head ].z + dz[ i ] ;
if( !vis[ xx ][ yy ][ zz ] && ( map[ xx ][ yy ][ zz ] == '.' ) && xx >= && xx < L && yy >= && yy < R && zz >= && zz < C ) {
vis[ xx ][ yy ][ zz ] = true ;
Q[ ++Tail ].x = xx ;
Q[ Tail ].y = yy ;
Q[ Tail ].z = zz ;
step [ Tail ] = step[ Head ] + ;
if ( Check ( xx , yy , zz ) ) return step[ Tail ] ;
}
}
++ Head ;
}
return false ;
} void Scan ( ) {
for ( int i= ; i<L ; ++i , getchar ( ) ){
for ( int j= ; j<R ; ++j , getchar ( ) ){
for ( int k= ; k<C ; ++k ) {
map[ i ][ j ][ k ] = getchar ( ) ;
if ( map[ i ][ j ][ k ] == 'S' ) {
start_x = i ;
start_y = j ;
start_z = k ;
}
else if ( map[ i ][ j ][ k ] == 'E' ) {
map[ i ][ j ][ k ] = '.' ;
des_x = i ;
des_y = j ;
des_z = k ;
}
}
}
}
} inline void Print ( int temp ) {
if( temp ) printf ( "Escaped in %d minute(s).\n" , temp ) ;
else printf ( "Trapped!\n" ) ;
} int main ( ) {
while ( scanf ( "%d %d %d\n " , &L , &R , &C ) == && L && R && C ) {
Init ( ) ;
Scan ( );
Print ( BFS( ) ) ;
}
return ;
}

2016-10-19 18:50:40

(完)

POJ 2251 题解的更多相关文章

  1. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  2. 【POJ 2251】Dungeon Master(bfs)

    BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...

  3. 【BFS】POJ 2251

    POJ 2251 Dungeon Master 题意:有一个地图,三维,走的方向是上下,左右,前后.问你最小步数从起始点走到出口. 思路:三维的BFS,就是多加一组状态,需要细心(不细心如我就找了半个 ...

  4. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  5. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

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

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

  7. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  8. [ACM训练] 算法初级 之 搜索算法 之 深度优先算法DFS (POJ 2251+2488+3083+3009+1321)

    对于深度优先算法,第一个直观的想法是只要是要求输出最短情况的详细步骤的题目基本上都要使用深度优先来解决.比较常见的题目类型比如寻路等,可以结合相关的经典算法进行分析. 常用步骤: 第一道题目:Dung ...

  9. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

随机推荐

  1. php无限分类

    无限循环 1.需要套2个foreach 2.2个foreach结构一样 纯代码获取数据 ){ $where['parent_id']= $parent_id; $res = $this->m-& ...

  2. 关于jquery 集合对象的 each和click方法的 思考 -$(this)的认识

    1, 很重要的是: each: 是 自动遍历 集合中所有 item的, 是自动的; click: 包括其他所有的 "事件", 如mouseX事件, keyX事件等, 都不是 自动 ...

  3. Hadoop 2.6.0+ZooKeeper+Hive HA高可用集群安装

    http://blog.csdn.net/totxian/article/details/45248399

  4. 【转~】初识贝塞尔曲线(Bézier curve)

    本文图文大多转自http://www.html-js.com/article/1628 QAQ我居然去扒维基,,,看不懂啊,,,我要去补数学,,, 在做变形小鸡的时候用到CSS3 transition ...

  5. Mac Pro 利用PHP导出SVN新增或修改过的文件

    先前在 Windows 操作系统下,习惯用 TortoiseSVN 导出新增或修改过的文件([相当实用]如何让TortoiseSVN导出新增或修改过的文件 ),最近换成了 Mac Pro 笔记本电脑, ...

  6. java基础知识(四)java内存机制

    Java内存管理:深入Java内存区域 上面的文章对于java的内存管理机制讲的非常细致,在这里我们只是为了便于后面内容的理解,对java内存机制做一个简单的梳理. 程序计数器:当前线程所执行的字节码 ...

  7. C和指针 第十二章 使用结构和指针 双链表和语句提炼

    双链表中每个节点包含指向当前和之后节点的指针,插入节点到双链表中需要考虑四种情况: 1.插入到链表头部 2.插入到链表尾部 3.插入到空链表中 4.插入到链表内部 #include <stdio ...

  8. [k]优雅的css

    1.图片文字列表 (2016-01-25) 1.1 实现效果图如下: 1.2 代码: html:( 代码十分优雅哦! ) <ul> <li class="step1&quo ...

  9. linux常用命令积累

    1.jps jps(Java Virtual Machine Process Status Tool)是JDK 1.5提供的一个显示当前所有java进程pid的命令,简单实用,非常适合在linux/u ...

  10. 我与A协

    大学毕业以后发现离曾经的圈子越来越远,非常怀念原来在A协和大家一起奋斗的日子,在这里写一篇文章,献给有很多美好回忆的A协,也献给渐渐远离A协的我. 首先,回顾一下我为什么会参与到A协的建设工作中来.我 ...