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. JavaScript:理解Promise方法

    什么是promise? Promise的核心思想是代表异步操作的一个结果,并且promise具有三个状态(pending初始状态,fulfilled成功状态,rejected失败状态).我们可以理解为 ...

  2. javascript:理解DOM事件

    首先,此文不讨论繁琐细节,但是考虑到读者的心灵感受,本着以积极向上的心态,在此还是会列举示例说明. ​标题为理解DOM事件,那么在此拿一个简单的点击事件为例,希望大家看到这个例子后能触类旁通. DOM ...

  3. 【翻译】22款HTML & CSS3 UI工具包免费下载

    下面盘点了22款适用于网页设计的HTML&CSS3 UI工具包,并且全部都是免费的哦!喜欢就赶紧 下载或收藏吧.这些免费工具可以加速你的网页开发进程,让你有更多时间专注于其他更重要的部分.由于 ...

  4. 【转】Web实时通信之Socket.IO ,真正的兼容ie

    前面两篇文章使用了Ajax long polling和WebSocket两种常用的Web实时通信方式构建了简单的聊天程序. 但是,由于浏览器的兼容问题,不是所有的环境都可以使用WebSocket这种比 ...

  5. empty、isset、is

    直接上代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <?php $a=0; $b='0'; $c=0.0; ...

  6. ubuntu install oracle jdk

    .Download the required tarball from here .unzip this tarball using "tar -zxvf tarball_name .cre ...

  7. Oracle Hint 之 Parallel

    强制启用oralce的多线程处理功能. 并行查询允许将一个sql select 语句划分为多个较小的查询,每个部分的查询并发的运行,然后将各个部分的结果组合起来,提供最终的结果,多用于全表扫描,索引全 ...

  8. 文件系统inodes使用率过高问题处理

    运维过程中经常碰见文件系统inodes使用率过高导致文件系统不可写的问题,常见场景如下 .Oracle产生的审计文件,特别是DG备库或者审计设置为OS时 .crontab产生大量邮件,导致/var/s ...

  9. 升级win10后电脑经常自动重启的问题

    升级win10后用户体验度确实比win7强了很多,但是电脑无故的重启,让人无法接受,下面就介绍win10电脑自动重启问题的解决方案 问题分析: 遇到这种情况主要是硬件与系统不兼容所致 解决方案: 1, ...

  10. vi中系统剪切板的设置

    在vi中,如果编译时没有clipboard属性,将vi中的内容拷贝到系统剪切板有些麻烦.可以用如下的方法,查看vi 是否支持系统剪切板的功能: xt@xt-ThinkPad-X220:~$ vi -- ...