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

(完)

最新文章

  1. ABP源码分析九:后台工作任务
  2. lua创建文件和文件夹
  3. [UCSD白板题] Least Common Multiple
  4. Magento开发常用方法
  5. Hibernate,JPA注解@SecondaryTables
  6. TControl的显示函数(5个非虚函数,4个虚函数)和三个例子的执行过程(包括SetParent的例子)
  7. B/S状态(同步)AJAX技术(异步)
  8. MapReduce调度与执行原理之作业初始化
  9. WebxFrameworkFilter 请求响应过程
  10. Mac 下卸载 Graphviz
  11. 前端跨域方案-跨域请求代理(node服务)
  12. mysqlclient和PyMySQL对比
  13. c语言基础学习01
  14. 【递推】ZSC1072: 数学、不容易系列之二—— LELE的RPG难题
  15. ******十三 ******、软设笔记【操作系统】-磁盘管理、虚设备与SPOOLing系统
  16. [k8s]k8s的控制层kubelet+docker配合调度机制(k8架构)
  17. array 的方法
  18. yarn 工作原理(2)
  19. LinkedList详解
  20. CentOS7上部署ASP.Net Core 2.2应用

热门文章

  1. QT中检索设定目录下所有指定文件的方法
  2. PHP图片上传类
  3. javascript数据结构与算法-- 二叉树
  4. UVA-11997 K Smallest Sums
  5. PHP获取指定月份的第一天开始和最后一天结束的时间戳函数
  6. vue2.0学习(二)
  7. mount img
  8. mediastreamer使用教程
  9. MFCC特征提取(C语言版本)
  10. Xtrabackup 安装使用