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. #pragma once

    这是一个比较常用的C/C++杂注,只要在头文件的最开始加入这条杂注,就能够保证头文件只被编译一次. #pragma once是编译器相关的,就是说即使这个编译系统上有效,但在其他编译系统也不一定可以, ...

  2. javascript的类和构造函数

    在javascript中,类的实现是基于其原型继承机制的.如果两个实例都从同一个原型对象上继承了属性,我们就说它们是同一个类的实例.那么,如果两个对象继承自同一个原型,那基本上可以认为它们是由同一个构 ...

  3. 一步一步学android控件(之十六)—— CheckBox

    根据使用场景不同,有时候使用系统默认的CheckBox样式就可以了,但是有时候就需要自定义CheckBox的样式.今天主要学习如何自定义CheckBox样式.在CheckBox状态改变时有时需要做一些 ...

  4. PHP基本语法(一)

    整形:就是对用整数  正整数与负整数整形的表示:int integer NOTICE:写整形的时候不要在外面再加引号了 浮点:就是小数 3.1415926Float 浮点 布尔值:男和女 真和假 阴和 ...

  5. 使用webview如何做超时判断

    在加载网页时给一个timer定时器,规定超时时间,然后再超时时间的方法中提示超时 如果没有超时,则在webview协议中的“加载完成”方法中 取消timer定时器 - (void)openWebVie ...

  6. 微信中QQ表情的解析(php)

    微信公众平台接受的消息中,标签是用'/:'开头的字符串表示的,假设要在网页上显示(比方制作微信大屏幕),就须要进行转换. 所以我向微信公众平台按顺序发送了各个QQ表情,在微信公众平台后台能够看到接受的 ...

  7. mongdb使用场景

    你期望一个更高的写负载 默认情况下,对比事务安全,MongoDB更关注高的插入速度.如果你需要加载大量低价值的业务数据,那么MongoDB将很适合你的用例.但是必须避免在要求高事务安全的情景下使用Mo ...

  8. cocos2d-x 3.0 Armature jsb 初体验

    有段时间没有写游戏代码了,这回来主要任务是要用jsb构建一个aprg动作游戏,看到3.0官方已经绑定好了armature的js函数,先来体验一把 3.0新建项目比2.2方便了很多,在终端运行tools ...

  9. Android 软件开发之 PreferenceActivity 中的组件

    1.PreferenceActivity 介绍 PreferenceActivity 继承ListActivity 它是以一个列表的形式在展现内容,它最主要的特点是添加Preference可以让控件的 ...

  10. android104 帧动画,补间动画,属性动画

    ##帧动画FrameAnimation* 多张图片快速切换,形成动画效果* 帧动画使用xml定义 package com.itheima.frameanimation; import android. ...