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. POJ-2195 Going Home---KM算法求最小权值匹配(存负边)

    题目链接: https://vjudge.net/problem/POJ-2195 题目大意: 给定一个N*M的地图,地图上有若干个man和house,且man与house的数量一致.man每移动一格 ...

  2. python操作文件目录

    # 查看当前目录的绝对路径: >>> os.path.abspath('.') /Users/NaCl/Documents/GitHub #同样的道理,要拆分路径时,也不要直接去拆字 ...

  3. 通过jQuery遍历div里面的checkbox

    遍历: $('#queryUser2 input[type="checkbox"]:checked').each( function () { a = a + $(this).va ...

  4. 关于多行文本 textarea 在ios 真机上padding相对安卓较大问题

    问题: 多行文本组件是带有默认的padding的,然而,小程序的teatarea 在ios和安卓上显示的padding不一样,普遍ios的padding会比安卓的要明显的大.这种情况下我的想法是做兼容 ...

  5. 问题:Could not install packages due to an EnvironmentError: [Errno 13] Permission denied:

    1.安装django 执行pip3 install --user django 2.解决方法:加--user   执行pip3 install --user django

  6. nginx下根据指定路由重定向

    前言: 最近在搭建vue后台,后端接口是PHP写的,线上构建好之后,需要请求其他域名下的接口,开发环境已经使用proxytable解决了接口问题,为了开发和生成的代码一致, 编译后的代码,放在ngin ...

  7. 卸载Redhat 7自带的yum,安装并使用网易163源

    由于redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,安装CentOS yum工具,再配置其他源,以下为详细过程:删除redhat原有的yum ...

  8. Java泛型和反射

    1. 字节码对象的三种获取方式 以String为例 Class<? extends String> strCls = "".getClass(); Class<S ...

  9. ES6-总结

    在最近进行的项目中,已经全面使用到ES6,这里对ES6进行整理总结.用得比较多的是带*的内容,这些语法.新增类型.模块调用等从代码量上.可读性上.操作上给项目带来了不少便利.   1.语法 1.1.命 ...

  10. 解决Linux使用php命令 -base comment not found并安装composer

    获取php的安装目录 使用 find / -name php.ini 查看php的安装位置 /usr/local/php/lib/php.ini # cd 到/usr/local/php/lib/ph ...