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!
//因为是三维寻找路径,又是最短路径,所以用bfs
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
char a[][][];
int b[][][];
int L,R,C;
int f[][]={{,-,, ,, },
{, ,,-,, },
{, ,, ,,-}};
int s2[][][];
int flag;
struct Knot
{
int x,y,z;
int step;
};
Knot c,d;
bool search1(int x,int y,int z)
{
return (x>=&&x<=L&&y>=&&y<=R&&z>=&&z<=C);
}
int bfs(int si,int sj,int sk)
{
queue<Knot>s;
c.x=si;
c.y=sj;
c.z=sk;
c.step=;
s.push(c);
while (!s.empty())
{
d=s.front();
s.pop();
c.step=d.step+;
for (int i=;i<;i++)
{
c.x=d.x+f[][i];
c.y=d.y+f[][i];
c.z=d.z+f[][i];
if (search1(c.x,c.y,c.z)&&!b[c.x][c.y][c.z]&&a[c.x][c.y][c.z]!='#')
{
if (a[c.x][c.y][c.z]=='E')
return c.step;
b[c.x][c.y][c.z]=;
s.push(c);
}
}
}
return -;
}
int main()
{
int i,j,k;
int si,sj,sk;
while (cin>>L>>R>>C&&(L!=||R!=||C!=))
{
memset(b,,sizeof(b));
for (i=;i<=L;i++)
for (j=;j<=R;j++)
for (k=;k<=C;k++)
{
cin>>a[i][j][k];
if (a[i][j][k]=='S')
{
si=i;
sj=j;
sk=k;
}
}
flag=bfs(si,sj,sk);
if (flag==-)
cout << "Trapped!" << endl;
else
cout << "Escaped in " << flag << " minute(s)." << endl; }
return ;
}

Dungeon Master (三维bfs)的更多相关文章

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

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

  2. POJ 2251 Dungeon Master (三维BFS)

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

  3. POJ:Dungeon Master(三维bfs模板题)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16748   Accepted: 6522 D ...

  4. ZOJ 1940 Dungeon Master 三维BFS

    Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Desc ...

  5. Dungeon Master(三维bfs)

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

  6. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

  7. 【POJ - 2251】Dungeon Master (bfs+优先队列)

    Dungeon Master  Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...

  8. 棋盘问题(DFS)& Dungeon Master (BFS)

    1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...

  9. Dungeon Master (简单BFS)

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

  10. POJ 2252 Dungeon Master 三维水bfs

    题目: http://poj.org/problem?id=2251 #include <stdio.h> #include <string.h> #include <q ...

随机推荐

  1. 使用bitmap实现对一千万个无重复的正整数(范围1~1亿)快速排序

    1 Bytes(字节) == 8 bit 1 KBytes == 1024 Bytes 思路: 1)申请长度为1亿的保存二进制位的数组 a, 2)通过位运算,将整数做为索引,将数组a对应的索引位置为1 ...

  2. opencv加椒盐噪声

    void salt(IplImage *img, int saltNum) { int x,y; int i ; unsigned char *src = NULL; src = (unsigned ...

  3. android stadio gradle问题

    https://www.jianshu.com/p/2bb0b6a7b479 https://www.jianshu.com/p/d175bef9770c Unable to resolve depe ...

  4. #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)

    题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...

  5. 洛谷 P1505 BZOJ 2157 [国家集训队]旅游

    bzoj题面 Time limit 10000 ms Memory limit 265216 kB OS Linux 吐槽 又浪费一个下午--区间乘-1之后,最大值和最小值更新有坑.新的最大值是原来最 ...

  6. 目标检测Object Detection概述(Tensorflow&Pytorch实现)

    1999:SIFT 2001:Cascades 2003:Bag of Words 2005:HOG 2006:SPM/SURF/Region Covariance 2007:PASCAL VOC 2 ...

  7. eclipse导出java项目jar包(依赖第三方jar包)

    一.在项目根目录下建一个文件:MANIFEST.MF 内容: Manifest-Version: 1.0 Class-Path: lib/commons-compress-1.9.jar lib/co ...

  8. 14 补充 MySQL的创建用户和授权

    权限管理 我们知道我们的最高权限管理者是root用户,它拥有着最高的权限操作.包括select.update.delete.update.grant等操作.那么一般情况在公司之后DBA工程师会创建一个 ...

  9. 高级软件测试技术-任务进度-Day03

    任务进度11-15 使用工具 Jira 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务进度 经过了前两天的学习任务的安排,以下是大家的任务进度: 穆同学(任务1) 1.今天就接着昨天的 ...

  10. SecureCRT使用+堡垒机简单使用

    写在前面的话 自从升级为宝妈后,回来发现好多东西都遗忘了.熟话说:好记性不如烂笔头,我还是记录下来吧. 堡垒机使用的几个技巧 1.快捷操作         1) 输入 ID 直接登录.         ...