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. hibernate jpa 注解 @Temporal(TemporalType.DATE) 格式化时间日期,页面直接得到格式化类型的值

    1.日期: @Temporal(TemporalType.DATE) @Column(name = "applyDate", nullable = false, length = ...

  2. 【转】Linux中安装Resin

      安装步骤: Ø  安装resin前先要保证安装了JDK,可以用命令查看是否安装了JDK: [root@wxr webapps]# java -versions java version " ...

  3. [Angular 2] Interpolation: check object exists

    In Angular2, sometime we use @Output to pass data to parent component, then parent may pass the data ...

  4. LDAP错误代码221

    ---------------------------命令方式启动失败报错-------------------------------[root@rusky bin]# ./dsadm start ...

  5. AIX-du

    du命令显示用于文件的块的数量.如果指定的File参数实际上是一个目录,就要报告该目录内的所有文件.如果没有提供 File参数,du命令使用当前目录内的文件.如果File参数是一个目录,那么报告的块的 ...

  6. UltraEdit环境下,php简单环境配置

    1.语法高亮 菜单->视图->查看方式->选中“PHP” 2.自动补全 菜单->高级->配置->自动完成->选中“自动显示自动完成对话框”,字符数选择2-3为 ...

  7. 从客户端检测到危险的Request.Form值解决方案

    1.修改aspx页面中的代码,设置ValidateRequest="false" <%@ Page Language="C#" AutoEventWire ...

  8. C#简单注册表操作实例

    1.简介操作 //设置注册值 private void Button_Click(object sender, RoutedEventArgs e) { //路径及间隔符号要正确 //1.如果指定路径 ...

  9. iOS_SN_CoreDate(一)封装使用

    看过一篇封装CoreData的文章挺不错,有基本使用封装,但是没有写怎么与tableView结合使用,我自己用的过程有些小波折,自己做了一个demo,大家可以看源码一些基本使用应该不难了, 原文:ht ...

  10. zepto源码研究 - deferred.js(jquery-deferred.js)

    简要:zepto的deferred.js 并不遵守promise/A+ 规范,而在jquery v3.0.0中的defer在一定程度上实现了promise/A+ ,因此本文主要研究jquery v3. ...