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

 
题意:一个3D的迷宫,问能否逃出去
直接bfs。。。
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<stdlib.h>
using namespace std;
int k,n,m;
char map[][][];
int vis[][][];
struct Node
{
int floor;
int x,y;
int t;
}st,ed;
int dirx[]={,,-,};
int diry[]={-,,,};
void bfs(Node s)
{
queue<Node>q;
q.push(s);
vis[s.floor][s.x][s.y]=;
Node t1,t2;
while(!q.empty())
{
t1=q.front();
q.pop();
if(t1.floor==ed.floor && t1.x==ed.x && t1.y==ed.y)
{
printf("Escaped in %d minute(s).\n",t1.t);
return;
} for(int i=;i<;i++)
{
t2.floor=t1.floor;
t2.x=t1.x+dirx[i];
t2.y=t1.y+diry[i];
if(t2.x>= && t2.x<n && t2.y>= && t2.y<m && !vis[t2.floor][t2.x][t2.y] && map[t2.floor][t2.x][t2.y]!='#')
{
vis[t2.floor][t2.x][t2.y]=;
t2.t=t1.t+;
q.push(t2);
}
}
t2=t1;
t2.floor=t1.floor+;
if(t2.floor< || t2.floor>=k) continue;
if(t2.x>= && t2.x<n && t2.y>= && t2.y<m && !vis[t2.floor][t2.x][t2.y] && map[t2.floor][t2.x][t2.y]!='#')
{
vis[t2.floor][t2.x][t2.y]=;
t2.t=t1.t+;
q.push(t2);
} t2=t1;
t2.floor=t1.floor-;
if(t2.floor< || t2.floor>=k) continue;
if(t2.x>= && t2.x<n && t2.y>= && t2.y<m && !vis[t2.floor][t2.x][t2.y] && map[t2.floor][t2.x][t2.y]!='#')
{
vis[t2.floor][t2.x][t2.y]=;
t2.t=t1.t+;
q.push(t2);
}
}
printf("Trapped!\n");
}
int main()
{
while(scanf("%d%d%d",&k,&n,&m)== && n+m+k!=)
{
for(int i=;i<k;i++)
{
for(int j=;j<n;j++)
{
scanf("%s",map[i][j]);
for(int l=;l<m;l++)
{
if(map[i][j][l]=='S')
{
st.floor=i;
st.x=j;
st.y=l;
st.t=;
}
if(map[i][j][l]=='E')
{
ed.floor=i;
ed.x=j;
ed.y=l;
}
}
}
}
memset(vis,,sizeof(vis));
bfs(st);
}
return ;
}

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

  1. POJ 2251 Dungeon Master(dfs)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

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

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

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

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

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

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

  5. POJ 2251 Dungeon Master (三维BFS)

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

  6. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  7. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

  8. 【POJ 2251】Dungeon Master(bfs)

    BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...

  9. POJ 2251 Dungeon Master(多层地图找最短路 经典bfs,6个方向)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48380   Accepted: 18252 ...

随机推荐

  1. C++基础学习笔记----第十三课(操作符重载-下)

    本节主要讲使用成员函数重载操作符,包括[],=,(),->四种操作符的重载以及&&和||的问题. 类的成员函数进行操作符重载 基本概念 类的成员函数也可以进行操作符的重载.类的普 ...

  2. 性能计数器自动收集-logman

    1.在桌面云测试中,往往需要模拟并发连接中服务器的性能数据,这里主要介绍如何自动收集性能数据 2.创建xxxx.bat文件,文件内容如下: logman create counter test -cf ...

  3. 如何用SVN进行个人版本管理

    事实上SVN的确是我用过的最好的源码管理工具,虽然我用过的这类工具并不多,只有VSS.CVS和SVN,其它像PVCS. TeamSource.ClearCase之类的只有耳闻,因为它们都是商业产品,并 ...

  4. Android-自定义PopupWindow

    PopupWindow在应用中应该是随处可见的,很常用到,比如在旧版本的微信当中就用到下拉的PopupWindow,那是自定义的.新版微信5.2的ActionBar,有人已经模仿了它,但微信具体是使用 ...

  5. 自定义listView添加滑动删除功能

    今天研究了一下android里面的手势,结合昨天学习的自定义View,做了一个自定义的listview,继承自listView,添加了条目的滑动手势操作,滑动后出现一个删除按钮,点击删除按钮,触发一个 ...

  6. 现代的新语言--Swift初探

    新的语言 WWDC简短的介绍,新的语言Swift就问世了,尽管新语言的名字导致贴吧下歌手粉丝和开发人员们争抢地盘- -,只是雨燕就是这么来了. WWDC keynote里给Swift打上了非常多标签: ...

  7. [Typescript] Function defination

    Define a function type and params type: // The function init // Accept two params which are both typ ...

  8. Python-xml解析常用方法简介

    [XML几种解析方法] 常见的XML编程接口有DOM和SAX,这两种接口处理XML文件的方式不同,使用场合自然也就不同. Python有三种方法解析XML: SAX,DOM,以及ElementTree ...

  9. <httpProtocol/>配置http协议头

    Web.Config中的位置 <configuration> <system.webServer> <httpProtocol> <!--http协议内容-- ...

  10. IE6不能用class命名!IE6不能用class命名!IE6不能用class命名! 重要的事情说3遍

    IE6不能用class命名!IE6不能用class命名!IE6不能用class命名!  重要的事情说3遍