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. log4j 配置文件 (XML/.properties)

    xml: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configurat ...

  2. [OS] 可执行文件的装载

    http://www.jianshu.com/p/e1300e7a4c48 1. 虚拟内存 在早期的计算机中,程序是直接运行在物理内存上的,程序在运行时访问的地址就是物理地址.可是,当计算机中同时运行 ...

  3. 漫谈 Clustering (番外篇): Vector Quantization

    在接下去说其他的聚类算法之前,让我们先插进来说一说一个有点跑题的东西:Vector Quantization.这项技术广泛地用在信号处理以及数据压缩等领域.事实上,在 JPEG 和 MPEG-4 等多 ...

  4. Oracle 函数 之 Coalesce()、greatest()、least()

    Coalesce().greatest().least() oracle比较一列的数据大小时,我们一般使用max()/min()函数,比较一行的最大值或者最小值时,使用函数Coalesce()/gre ...

  5. C程序设计语言 -- 运算符优先级

    1. 运算符分类 算术运算符            [+, -,*, /, % , ++, --] 关系运算符             [>,  >=, <, <=] 相等性运 ...

  6. NoSQL - KVstore -Redis

    Redis键迁移 在使用Redis的过程中,很多时候我们会遇到需要进行键迁移的问题,需要将指定Redis中的指定数据迁移到其他Redis当中,键迁移有三种方法,我们来进行一一介绍. 一.move mo ...

  7. 前端JS转图片为base64并压缩、调整尺寸脚本

    image to base64 to blob //////////////////////////////////////////////////////////////////////////// ...

  8. js浮点数加减乘除

    浮点数精确计算 /** ** 加法函数,用来得到精确的加法结果 ** 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显.这个函数返回较为精确的加法结果. ** 调用:ac ...

  9. 第11课 文章分类(组件化开发) Thinkphp5商城第四季

    目录 思路: 控制器里 扩展类里: 视图层: 思路: 控制器查出所有数据后调用扩展类里的无限级分类 public function catetree($cateRes) 方法. 把排序好的数据传给视图 ...

  10. LA_3942 LA_4670 从字典树到AC自动机

    首先看第一题,一道DP+字典树的题目,具体中文题意和题解见训练指南209页. 初看这题模型还很难想,看过蓝书提示之后发现,这实际上是一个标准DP题目:通过数组来储存后缀节点的出现次数.也就是用一颗字典 ...