Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21230   Accepted: 8261

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!

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<stdio.h>
#include<string.h>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
bool vis[][][];
char str[][][];
int step;
int nex[][]={,,,,,-,,,,-,,,,,,,-,};
struct node{
int x,y,z;
int dis;
};
node u,v;
int x,y,z;
int bfs(){
// printf("--->%d %d %d\n",u.x,u.y,u.z);
queue<node>q;
q.push(u);
vis[u.z][u.x][u.y]=true;
while(!q.empty()){
u=q.front();
q.pop();
if(str[u.z][u.x][u.y]=='E')
return u.dis;
for(int i=;i<;i++){
v.x=u.x+nex[i][];
v.y=u.y+nex[i][];
v.z=u.z+nex[i][];
if(str[v.z][v.x][v.y]!='#'&&!vis[v.z][v.x][v.y]&&v.x>=&&v.x<x&&v.y>=&&v.y<y
&&v.z>=&&v.z<z){
vis[v.z][v.x][v.y]=true;
v.dis=u.dis+;
q.push(v);
}
} }
return ;
} int main(){ while(scanf("%d%d%d",&z,&x,&y)!=EOF){
if(x==&&y==&&z==)
break;
memset(str,,sizeof(str));
memset(vis,false,sizeof(vis));
for(int k=;k<z;k++){
for(int i=;i<x;i++){
scanf("%s",str[k][i]);
for(int j=;j<y;j++){
if(str[k][i][j]=='S')
u.x=i,u.y=j,u.z=k,u.dis=;
}
}
}
step=;
step=bfs();
if(step>)
printf("Escaped in %d minute(s).\n",step);
else
printf("Trapped!\n");
}
return ;
}

poj 2251 Dungeon Master 3维bfs(水水)的更多相关文章

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

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

  2. 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 ...

  3. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

  4. POJ 2251 Dungeon Master(三维空间bfs)

    题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...

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

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

  6. BFS POJ 2251 Dungeon Master

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

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

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

  8. 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 ...

  9. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

随机推荐

  1. 初见微服务之RESTful API

    1. REST名称由来 REST全称为Representational State Transfer,即表述性状态转移,最早由Roy Feilding博士在世纪之交(2000年)提出,喜欢追根溯源的朋 ...

  2. oc语言特性

    It’s a superset of the C programming language and provides object-oriented capabilities and a dynami ...

  3. ETL工具--DataX3.0实战

    DataX是一个在异构的数据库/文件系统之间高速交换数据的工具,实现了在任意的数据处理系统(RDBMS/Hdfs/Local filesystem)之间的数据交换,由淘宝数据平台部门完成. DataX ...

  4. java基础面试题:请说出作用域public,private,protected,以及不写时的区别

    不写任何作用域(即访问权限)表示friendly public 公共,权限最大,作用域最大,在类内部.同一package.子孙类.其他package都可以访问 protected保护,在类内部.同一p ...

  5. notify()和notifyAll()主要区别

    notify()和notifyAll()都是Object对象用于通知处在等待该对象的线程的方法. void notify(): 唤醒一个正在等待该对象的线程.void notifyAll(): 唤醒所 ...

  6. 1074: [SCOI2007]折纸origami

    Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 372  Solved: 229[Submit][Status][Discuss] Descriptio ...

  7. visio画图ER图表和字段注释

    最近年底属于验收的项目很多,大多数写文档中,数据库的设计ER图是比不可少的.下面记一下几个常用的用法.以下用的市visio版本为2007,由于菜单样式新版本可能有所不同,请对照相应功能进行操作! 1. ...

  8. JS — 实现简单的数字时钟

    js实现简单的数字时钟 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...

  9. JZOJ 3470. 【NOIP2013模拟联考8】最短路(path)

    470. [NOIP2013模拟联考8]最短路(path) (Standard IO) Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed ...

  10. POJ 2586 贪心+枚举

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15626   Accepted: 78 ...