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. Log Parser 微软强大的日志分析工具

    Log Parser(微软网站下载)是微软公司出品的日志分析工具,它功能强大,使用简单,可以分析基于文本的日志文件.XML 文件.CSV(逗号分隔符)文件,以及操作系统的事件日志.注册表.文件系统.A ...

  2. pes and ts stream, how to convert

    http://stackoverflow.com/questions/4145575/transport-stream-mpeg-file-fromat What you are probably w ...

  3. linux进程,作业,守护进程,进程间同步

    ps axj命令查看系统中的进程.参数a表示不仅列当前用户的进程,也列出所有其他用户的进程,参数x表示不仅列有控制终端的进程,也列出所有无控制终端的进程,参数j表示列出与作业控制相关的信息: 凡是TP ...

  4. poj 2942--Knights of the Round Table (点的双连通分量)

    做这题简直是一种折磨... 有n个骑士,骑士之间相互憎恨.给出骑士的相互憎恨的关系. 骑士要去开会,围成一圈坐,相互憎恨的骑士不能相邻.开会骑士的个数不能小于三个人.求有多少个骑士不能开会. 注意:会 ...

  5. 教程-Delphi7 自带控件安装对应表

    原来的控件delphi7里何处寻? 经常有朋友提这样的问题,“我原来在delphi5或者delphi6中用的很熟的控件到哪里去了?是不是在delphi7中没有了呢?这是不是意味着我以前写的代码全都不能 ...

  6. 理解screenX clientX pageX概念

    先了解screenX,clientX,pageX概念 screenX: 鼠标位置相对于用户屏幕水平偏移量,而screenY就是垂直方向的,此时的参照点也就是原点是屏幕的左上角. clientX: 跟s ...

  7. python学习之列表

    #coding:utf-81.#reverse方法将列表的元素反向存放,改变了原列表但不返回值x=[5,2,4,3,8]x.reverse() #x[::-1] 不改变list反向排序print x ...

  8. JSON基本操作

    import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.J ...

  9. Ubuntu 14.10安装SecureCRT 7.3

    Ubuntu 14.10下安装SecureCRT 7.3 1.软件准备 Ubuntu14.10 x64 SecureCRT7.3的版本:scrt-7.3.0-657.ubuntu13-64.x86_6 ...

  10. 结构体数组(C++)

    1.定义结构体数组 和定义结构体变量类似,定义结构体数组时只需声明其为数组即可.如: struct Student{ int num; char name[20]; char sex[5]; int ...