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. 内嵌cuzySDK的App——礼物购已登陆App store

    内嵌cuzySDK的App——礼物购已登陆App store.每天为你搜罗特别的礼物,可分类挑选礼物,直接连接淘宝购买,做最贴心的小清新礼物助手,欢迎各位亲朋好友去下载体验.@cuzySDK  @re ...

  2. mfc socket编程

    socket编程用法---- 随着计算机网络化的深入,计算机网络编程在程序设计的过程中变得日益重要.由于C++语言对底层操作的优越性,许多文章都曾经介绍过用VC++进行Socket编程的方法.但由于都 ...

  3. 50个android开发技巧

    50个android开发技巧 http://blog.csdn.net/column/details/androidhacks.html

  4. Java基础知识强化57:经典排序之希尔排序(ShellSort)

    1. 希尔排序的原理: 希尔排序(Shell Sort)是插入排序的一种.也称缩小增量排序,是直接插入排序算法的一种更高效的改进版本.希尔排序是非稳定排序算法.该方法因DL.Shell于1959年提出 ...

  5. 邮件发送 EMailHelper

    引用: using System; using System.Collections.Generic; using System.Linq; using System.Net; using Syste ...

  6. scala学习笔记——类和对象

    基础语法关于Scala程序,这是非常要注意以下几点. 区分大小写 - Scala是大小写敏感的,这意味着标识Hello 和 hello在Scala中会有不同的含义. 类名 - 对于所有的类名的第一个字 ...

  7. 使用证书部署出现System.Security.Cryptography.CryptographicException 错误解决方案

    一.System.Security.Cryptography.CryptographicException: 找不到对象 at System.Security.Cryptography.Cryptog ...

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

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

  9. C/C++中字符串存储位置

    代码: #include <iostream> #include <cstdio> using namespace std; void fun(char **p){ //cha ...

  10. 求解:C#.Net 远程方法调用失败 (Exception from HRESULT: 0x800706BE)

    服务器:Windows Server2003 sp2服务器 客户端:XP SP3 内容:C#Winform客户端调用服务器的Excel模板生成报表的时候,生成失败,抛出的异常如下: TargetInv ...