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<iostream>
#include<queue>
#include<cstdio>
using namespace std;
const int N=40;
int h,m,n,s,x,y,z;
char a[N][N][N];
int dl[6][3]={{0,0,-1},{0,0,1},{0,-1,0},{0,1,0},{1,0,0},{-1,0,0}};
struct loc
{
int x,y,z,cnt;
loc(int x,int y,int z,int cnt):x(x),y(y),z(z),cnt(cnt){}
};
int pd(int x,int y,int z)
{
if(x<0||x>h||y<0||y>m||z<0||z>n) return 0;
else if(a[x][y][z]=='#')return 0;
else if(a[x][y][z]=='E') return -1;
else if(a[x][y][z]=='.') return 1;
else return 0;
}
int main()
{
queue<loc>dem;
while(cin>>h>>m>>n){
if(h==0)break;
for(int i=0;i<h;i++)
for(int j=0;j<m;j++)
for(int k=0;k<n;k++)
{
cin>>a[i][j][k];
if(a[i][j][k]=='S')x=i,y=j,z=k;
}
while(!dem.empty())dem.pop();
loc tem(x,y,z,0);
dem.push(tem);
while(!dem.empty())
{
tem=dem.front();
a[tem.x][tem.y][tem.z]='#';
dem.pop();
for(int i=0;i<6;i++)
{
if(pd(tem.x+dl[i][0],tem.y+dl[i][1],tem.z+dl[i][2])==-1)
{
loc t(tem.x+dl[i][0],tem.y+dl[i][1],tem.z+dl[i][2],tem.cnt+1);
tem=t;
goto en;
//cout<<tem.x+dl[i][0]<<' '<<tem.y+dl[i][1]<<' '<<tem.z+dl[i][2]<<endl;
}
else if(pd(tem.x+dl[i][0],tem.y+dl[i][1],tem.z+dl[i][2])==1)
{
loc t(tem.x+dl[i][0],tem.y+dl[i][1],tem.z+dl[i][2],tem.cnt+1);
dem.push(t);
a[t.x][t.y][t.z]='#';
//cout<<tem.x+dl[i][0]<<' '<<tem.y+dl[i][1]<<' '<<tem.z+dl[i][2]<<endl;
}
}
} cout<<"Trapped!"<<endl;
continue;
en: printf("Escaped in %d minute(s).\n",tem.cnt);
}
}

POJ - 2251 Dungeon Master(搜索)的更多相关文章

  1. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

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

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

  3. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

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

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

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

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

  6. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  7. POJ 2251 Dungeon Master (三维BFS)

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

  8. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

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

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

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

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

随机推荐

  1. 07-JDBC协议

    1.下载mysql-connector-java-8.0.17.jar,jar包放进jmeter的安装目录lib文件夹下,启动jmeter就好 2.新增线程组,然后添加配置元件:JDBC connec ...

  2. Docker命名空间

    命名空间 命名空间( namespace )是 Linux 内核的一个强大特性,为容器虚拟化的实现带来极大便利,利用这 特性,每个容器都可以拥有自己单独的命名空间,运行在其中的应用都像是在独立的操作系 ...

  3. 加锁的位置 (eq:map<key,map<>> 双集合 怎么 只加锁 在用到的对象位置,而不是把整个集合锁住)

    比如上边的map里套map 定义变量为data,例如组队副本 npc 为1 下有众多房间 即Map<1,<roomId,room>> ,处于多线程下,一个线程在 npc为1的下 ...

  4. 选择IT行业的自我心得,希望能帮助到各位!(二)

    在前面说道的一,希望大家能喜欢,这也只是自己的一种经历,每个人都有年轻的时候,谁的年级都有自以为是,谁的年轻都有风华正茂,谁的年轻都让自己的内涵给我们自己摔了一个狠狠的道理,人外有人天外有天.我记得当 ...

  5. Python程序设计实验报告一:熟悉IDLE和在线编程平台

    安徽工程大学 Python程序设计 实验报告 班级   物流191   姓名  崔攀  学号3190505136 成绩_____           日期     2020.3.8     指导老师  ...

  6. F - Minimum Sum LCM

    LCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is a multip ...

  7. JS Math&Date的方法 (下)

    Date - 时间日期对象 一:Date 时间对象 - 它是处理时间日期的 时间日期对象  - js提供了一个专门用来创建日期对象的构造函数 Date          new Date()  这是一 ...

  8. java文件上传、下载、图片预览

    多文件保存到本地: @ResponseBody    @RequestMapping(value = "/uploadApp",produces = { "applica ...

  9. 2020-3 网络对抗技术 20175120 exp5 信息搜集与漏洞扫描

    目录 实践目标 实践内容 各种搜索技巧的应用 搜索特定类型的文件Google Hacking 搜索网站目录结构 DNS IP注册信息的查询 网络侦查 基本的扫描技术:主机发现.端口扫描.OS及服务版本 ...

  10. CTFHub web技能树之RCE初步 命令注入+过滤cat

    在一个大佬的突然丢了个题过来,于是去玩了玩rce的两道题 大佬的博客跳转链接在此->>>大佬召唤机 叫 命令注入 一上来就是源码出现,上面有个ping的地方 <?php $re ...