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. 萌新带你开车上p站(一)

    本文作者:萌新 0x01前言 这一系列文章为pwnable.krToddlr’s Bottle的全部题解,其中有三道题目相对而言稍难或者说比较经典,单独成篇,其他题目的题解放在一起发出来. 0x02f ...

  2. 2020-3-30 20175110王礼博 Exp3 免杀原理与实践

    目录 1.正确使用msf编码器 2.msfvenom生成如jar之类的其他文件 3.veil 4.加壳工具 5.使用C + shellcode编程 6.使用其他课堂未介绍方法 7.通过组合应用各种技术 ...

  3. centos7 ip/映射/机器名变更/克隆(克隆后配置修改)|2

    1.  查看主机名,三个命令都可以 # hostname # uname -n # cat  /proc/sys/kernel/hostname 2.    使用 vi /etc/hostname 文 ...

  4. 深入了解CI/CD:工具、方法、环境、基础架构的全面指南

    本文来自Rancher Labs 持续集成和持续交付(CI/CD)是DevOps背后的助推力之一.如果你的企业正在考虑使用DevOps,那么CI/CD绝对是需要考虑的其中一部分.但是CI/CD到底意味 ...

  5. 条件变量 condition_variable wait_for

    wait_for(阻塞当前线程,直到条件变量被唤醒,或到指定时限时长后) #include <iostream> #include <atomic> #include < ...

  6. x聊之后,又一波新的诈骗套路

    前些天刚看到,x聊勒索诈骗套路,骗子的套路可以说是花样百出,这不又一网友深受其害. 事情经过是这样的 某被骗网友由于工资微薄一直想找副业增加收入,关注和加了很多群. 注意群里都是有偏亮头像的”小姐姐” ...

  7. 聊聊Disruptor 和 Aeron 这两个开源库

    Disruptor The best way to understand what the Disruptor is, is to compare it to something well under ...

  8. 深入理解new运算符

    在 JavaScript 中,new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例.创建一个对象很简单,为什么我们还要多此一举使用 new 运算符呢?它到底有什么样的魔力? 认 ...

  9. Daily Scrum 1/4/2015

    Process: After New year's Day, we start our project in plan. Zhanyang: Add some useful UI in the IOS ...

  10. JavaScript的运行机制!!!很重要很重要!!!!!!请看大神操作!

    https://juejin.im/post/59e85eebf265da430d571f89