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! 问题分析:依旧是简单bfs,但是要用三维数组储存地图,但是有6个分支,用数组来储存方向可以让程序更简洁。
 #include "iostream"
#include "queue"
using namespace std;
char maze[][][];
int v[][]={,,-,,,,,-,,,,,-,,,,,};
int L,R,C;
struct escaper
{
int i;
int j;
int k;
int time;
};
escaper fir;
void mbegin()
{
for (int i=;i<=L+;i++)
for (int j=;j<=R+;j++)
for (int k=;k<=C+;k++)
if (i*j*k == || i == L+ || j==R+ || k==C+)
maze[i][j][k] = '#';
else
{
cin>>maze[i][j][k];
if (maze[i][j][k] == 'S')
{
fir.i = i;
fir.j = j;
fir.k = k;
}
}
}
void bfs()
{
queue <escaper> p;
escaper sec;
fir.time=;
p.push(fir);
while (!p.empty())
{
sec = p.front();
p.pop();
for (int i=;i<;i++)
{
fir.i = sec.i+v[i][];
fir.j = sec.j+v[i][];
fir.k = sec.k+v[i][];
if (maze[fir.i][fir.j][fir.k] != '#')
{
fir.time = sec.time+;
if (maze[fir.i][fir.j][fir.k] == 'E')
{
cout<<"Escaped in "<<fir.time<<" minute(s)."<<endl;
return;
}
maze[fir.i][fir.j][fir.k] = '#';
p.push(fir);
}
}
}
cout<<"Trapped!"<<endl;
}
int main()
{
while (cin>>L>>R>>C && L && R && C)
{
mbegin();
bfs();
}
return ;
}

暑假集训(1)第三弹 -----Dungeon Master(Poj2251)的更多相关文章

  1. 暑假集训(2)第三弹 ----- 食物链(poj1182)

    C - 食物链 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:10000KB     64bit ...

  2. 暑假集训(4)第三弹 -----递推(Hdu1799)

    问题描述:还记得正在努力脱团的小A吗? 他曾经最亲密的战友,趁他绘制贤者法阵期间,暗中设下鬼打墙将小A 围困,并准备破坏小A正在绘制的法阵.小A非常着急.想阻止他的行动.而要阻止他,必须先破解鬼打墙. ...

  3. 暑假集训(3)第三弹 -----Til the Cows Come Home(Poj2387)

    题意梗概:据说母牛在产奶的时候,因为奶量太充足,希望有人帮它挤奶,它回家就很快.我们便能喝到鲜美的 牛奶,不过,贫奶季节却大不相同,它会懒洋洋的在大草原上晃来晃去的晒太阳,而不会想到马上回家,这可不 ...

  4. bfs—Dungeon Master—poj2251

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32228   Accepted: 12378 ...

  5. 暑假集训(4)第六弹——— 组合(poj1067)

    题意概括:上一次,你成功甩掉了fff机械兵.不过,你们也浪费了相当多的时间.fff团已经将你们团团包围,并且逐步 逼近你们的所在地.面对如此危机,你不由得悲观地想:难道这acm之路就要从此中断?虽然走 ...

  6. 暑假集训(2)第七弹 -----今年暑假不AC(hdu2037)

    J - 今年暑假不AC Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64 ...

  7. 暑假集训(4)第五弹——— 数论(hdu1222)

    题意概括:那天以后,你好说歹说,都快炼成三寸不烂之舍之际,小A总算不在摆着死人脸,鼓着死鱼眼.有了点恢复的征兆.可孟子这家伙说的话还是有点道理,那什么天将降....额,总之,由于贤者法阵未完成,而小A ...

  8. 暑假集训(4)第八弹——— 组合(hdu1524)

    题意概括:你已经赢得两局,最后一局是N个棋子往后移动,最后一个无法移动的玩家失败. 题目分析:有向无环图sg值游戏,尼姆游戏的抽象表达.得到每个棋子的sg值之后,把他们异或起来,考察异或值是否为0. ...

  9. 暑假集训(4)第七弹——— 组合(hdu1850)

    题意概括:你赢得了第一局.魔鬼给出的第二局是,如果有N堆牌,先手的人有几种可能胜利. 问题分析:尼姆游戏,先得到n堆牌的数量异或和,再将异或和与每一个牌组的数量异或,如果结果小于原牌组数量 则可能++ ...

随机推荐

  1. A Tour of Go Making slices

    Slices are created with the make function. It works by allocating a zeroed array and returning a sli ...

  2. JavaScript- The Good Parts Chapter 5 Inheritance

    Divides one thing entire to many objects;Like perspectives, which rightly gazed uponShow nothing but ...

  3. hdoj 2 括号配对问题【数组模拟实现+STL实现】

    栈遵循先进后出的原则 括号配对问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 现在,有一行括号序列,请你检查这行括号是否配对.   输入 第一行输入一个数N(0 ...

  4. 在SCVMM2012R2中删除失去联系的VM GateWay

    当VM Gateway失去联系,无法使用,直接删除GW,或者在VM Network中删除GW连接,均会出现如下错误提示: 错误(21426)对配置提供程序 4ee559f1-f479-480c-945 ...

  5. 2假动作,数据缓冲,CCEaseExponential,CCEaseElastic,CCEaseBounce,CCCallFunc,funcNCallBack,funcNDCallBack,funcO

     1 缓冲动作 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/4 ...

  6. CentOS开发环境LAMP搭建

    CentOS开发环境搭建 -------------------------------------------------------------------------准备工作---------- ...

  7. Android AlertDialog 设置setSingleChoiceItems不显示列表的原因【setMessage和setSingleChoiceItems不能同时使用】

    今日写了个如题目的简单功能,结果列表不显示 无奈重写了一次代码发现setMessage和setSingleChoiceItems不能同时使用. 正确的如下: private void mobilePh ...

  8. Foundation: NSNotificationCenter

    一个NSNotificationCenter对象(通知中心)提供了在程序中广播消息的机制,它实质上就是一个通知分发表.这个分发表负责维护为各个通知注册的观察者,并在通知到达时,去查找相应的观察者,将通 ...

  9. OC最实用的runtime总结,面试、工作你看我就足够了!

    前言 runtime的资料网上有很多了,部分有些晦涩难懂,我通过自己的学习方法总结一遍,主要讲一些常用的方法功能,以实用为主,我觉得用到印象才是最深刻的,并且最后两个demo也是MJExtension ...

  10. 解锁Dagger2使用姿势(一)

    毫无疑问,Dagger2的 上手是有门槛的,有门槛是因为它里边的概念多,用起来复杂,可是一旦你学会了Dagger2的使用,你一定会爱不释手的.与ButterKnife和AndroidAnnotatio ...