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! 代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
char Map[][][];
int vis[][][];
struct node
{
int x,y,z;
int cnt;
};
using namespace std;
int sx,sy,sz;
int ex,ey,ez;
int dir[][]={{,,},{,,-},{-,,},{,,},{,,},{,-,}};
int s;
bool check(int x,int y,int z)
{
if((Map[z][x][y]=='.'||Map[z][x][y]=='E')&&vis[z][x][y]==)
{
return true;
}
else
{
return false;
}
}
bool bfs()
{
node start;
start.x=sx;
start.y=sy;
start.z=sz;
start.cnt=;
queue<node>q;
q.push(start);
vis[sz][sx][sy]=;
while(!q.empty())
{
node now=q.front();
q.pop();
//printf("%d %d %d\n",now.z,now.x,now.y);
if(now.z==ez&&now.x==ex&&now.y==ey)
{
s=now.cnt;
return true;
}
for(int t=;t<;t++)
{
node next;
next.x=now.x+dir[t][];
next.y=now.y+dir[t][];
next.z=now.z+dir[t][];
next.cnt=now.cnt+;
if(check(next.x,next.y,next.z))
{
vis[next.z][next.x][next.y]=;
q.push(next);
} }
}
return false;
}
int main()
{
int L,R,C;
while(scanf("%d%d%d",&L,&R,&C)!=EOF)
{
memset(vis,,sizeof(vis));
if(L==&&R==&&C==)
{
break;
}
s=;
for(int t=;t<L;t++)
{
for(int j=;j<R;j++)
{
scanf("%s",Map[t][j]);
}
}
for(int t=;t<L;t++)
{
for(int j=;j<R;j++)
{
for(int k=;k<C;k++)
{
if(Map[t][j][k]=='S')
{
sx=j;
sy=k;
sz=t;
}
if(Map[t][j][k]=='E')
{
ex=j;
ey=k;
ez=t;
}
}
}
} if(bfs())
printf("Escaped in %d minute(s).\n",s);
else
{
printf("Trapped!\n");
}
} 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. UVa532 Dungeon Master 三维迷宫

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

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

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

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

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

  8. Dungeon Master (简单BFS)

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

  9. POJ 2252 Dungeon Master 三维水bfs

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

随机推荐

  1. Docker之Ubuntu上使用Docker的简易教程

    Ubuntu上使用Docker的简易教程 原始文档:https://www.yuque.com/lart/linux/fp6cla 说在开头 在天池的比赛中涉及到了docker的使用.经过多番探究,大 ...

  2. ASP.NET Core Logging Solution

    Serilog.Extensions.Logging.File This package makes it a one-liner - loggerFactory.AddFile() - to con ...

  3. syslog协议及rsyslog服务全解析

    背景:需求来自于一个客户想将服务器的日志转发到自己的日志服务器上,所以希望我们能提供这个转发的功能,同时还要满足syslog协议. 一.什么是syslog协议 1.介绍(略) 2.syslog标准协议 ...

  4. Python面向对象编程扑克牌发牌程序,另含大量Python代码!

    1. 题目 编写程序, 4名牌手打牌,计算机随机将52张牌(不含大小鬼)发给4名牌手,在屏幕上显示每位牌手的牌. 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不 ...

  5. 一切尽在掌控之中:这个Python脚本,让工作自动向你汇报进度!

    图源:unsplash 笔者经常编写Python脚本来进行数据处理.数据传输和模型训练.随着数据量和数据复杂性的增加,运行脚本可能需要一些时间.在等待数据处理完成时可以同时做一些其他工作. 很多人学习 ...

  6. 使用Tensorflow搭建自编码器(Autoencoder)

    自编码器是一种数据压缩算法,其中数据的压缩和解压缩函数是数据相关的.从样本中训练而来的.大部分自编码器中,压缩和解压缩的函数是通过神经网络实现的. 1. 使用卷积神经网络搭建自编码器 导入MNIST数 ...

  7. 用WindowsAPI实现文件复制功能

    用WindowsAPI实现文件复制功能 1. c代码 注释也在里面 文件名为 copyfile.c 运行出来的exe为 copyfile.exe #include <windows.h> ...

  8. 使用 VMware Workstation Pro 让 PC 提供云桌面服务——学习笔记(一)

    最终效果: 能够通过xshell等终端设备, 远程访问虚拟机 操作步骤 1. 安装VMware 网上自行下载VMware 软件,这里不给出详细操作 2. 下载安装系统 这里使用 Centos 的lin ...

  9. s2-001漏洞复现

    struts2-001 该漏洞因为用户提交表单数据并且验证失败时,后端会将用户之前提交的参数值使用 OGNL 表达式 %{value} 进行解析,然后重新填充到对应的表单数据中.例如注册或登录页面,提 ...

  10. MySQL设置跳过密码验证

    1.linux系统下 在/etc/my.cnf文件中, [mysqld]下面新增skip-grant-tables,然后重启服务器.