Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21242   Accepted: 8265

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!
三维BFS 注意xyz别弄混了
/* ***********************************************
Author :pk29
Created Time :2015/8/19 18:40:40
File Name :4.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
struct node{
int x,y,z;
int dist;
};
bool cmp(int a,int b){
return a>b;
}
int l,r,c;
char mp[][][];
int vis[][][];
int sx,sy,sz,ex,ey,ez;
int dir[][]={,,,,,,,,-,,,,-,,,,-,}; void bfs(){
node u,v;
u.x=sx,u.y=sy,u.z=sz, u.dist=;
queue<node>q;
q.push(u);
int mark=;
vis[u.x][u.y][u.z]=;
while(!q.empty()){
u=q.front(),q.pop();
if(u.x==ex&&u.y==ey&&u.z==ez){
mark=;printf("Escaped in %d minute(s).\n",u.dist);break;
}
for(int i=;i<;i++){
int nx=u.x+dir[i][];
int ny=u.y+dir[i][];
int nz=u.z+dir[i][];
if(!vis[nx][ny][nz]&&mp[nx][ny][nz]!='#'&&nx>=&&ny>=&&nz>=&&nx<=r&&ny<=c&&nz<=l){
v.x=nx,v.y=ny,v.z=nz;
v.dist=u.dist+;
q.push(v);
vis[nx][ny][nz]=;
}
}
}
if(!mark)printf("Trapped!\n");
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
while(cin>>l>>r>>c){
if(l==&&c==&&r==)break;
for(int i=;i<=l;i++)
for(int j=;j<=r;j++)
for(int k=;k<=c;k++){
cin>>mp[j][k][i];
if(mp[j][k][i]=='S')sx=j,sy=k,sz=i;
if(mp[j][k][i]=='E')ex=j,ey=k,ez=i;
}
cle(vis);
//cout<<sx<<sy<<sz<<endl;
//cout<<ex<<ey<<ez<<endl; bfs();
}
return ;
}

最新文章

  1. linux 下如何 makefile
  2. 转帖:用五分钟重温委托,匿名方法,Lambda,泛型委托,表达式树
  3. 用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(1)-- 绘写文字
  4. poj2642 The Brick Stops Here(DP基础题)
  5. 【leetcode❤python】 205. Isomorphic Strings
  6. HTML5自学笔记[ 15 ]canvas绘图基础6
  7. [转]JAVA中Action层, Service层 ,modle层 和 Dao层的功能区分
  8. hdu 4333(扩展kmp)
  9. C#与C++对应的类型
  10. nodejs创建express+ejs项目
  11. 5亿投资A站G站:中文在线的二次元野心
  12. ps设计资料整理
  13. BackTrack 5 R3 Metasploit更新方法及msfupdae,msconsole出错解决办法
  14. 分分钟带你玩转 Web Services【2】CXF
  15. nginx静态服务器配置
  16. Linux系统的shell是什么
  17. C#多线程之旅~上车吧?
  18. 【easy】532. K-diff Pairs in an Array
  19. html5-表单的综合实例
  20. debian8.4 ibus中文输入法

热门文章

  1. 刷题总结——瞭望塔(bzoj1038)
  2. 刷题总结——过河(NOIP2015)
  3. spring之注入类型
  4. Redis的持久化——AOF
  5. java面试题之什么是死锁、活锁、饿死和竞态条件?
  6. Resin Thread Dump
  7. (8)C#连sqlserver
  8. jsp/servlet实现简单上传和下载
  9. Flink的安装配置
  10. android 按两次物理返回键退出程序