http://poj.org/problem?id=2251

Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 18773   Accepted: 7285

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! 分析:
典型的三维广搜。 AC代码:
 #include<cstdio>
#include<cstring>
#include<queue>
using namespace std; #define INF 0x3f3f3f3f char maz[][][];
int d[][][];
int sx,sy,sz;
int ex,ey,ez;
int dx[] = {,-,,,,};
int dy[] = {,,,-,,};
int dz[] = {,,,,,-};
int X,Y,Z;
struct P{
int x,y,z;
P(int xx,int yy,int zz) :x(xx),y(yy),z(zz) {
}
}; int bfs() {
memset(d,INF,sizeof(d));
queue<P> que;
que.push(P(sx,sy,sz));
d[sx][sy][sz] = ; while(que.size()) {
P p = que.front();que.pop(); if(p.x == ex && p.y == ey && p.z == ez) break; for(int i = ;i < ;i++) {
int nx = p.x + dx[i];
int ny = p.y + dy[i];
int nz = p.z + dz[i]; if( <= nx && nx < X && <= ny && ny < Y && <= nz && nz < Z
&& maz[nx][ny][nz] != '#' && d[nx][ny][nz] == INF) {
que.push(P(nx,ny,nz));
d[nx][ny][nz] = d[p.x][p.y][p.z] + ;
}
}
}
if(d[ex][ey][ez] == INF) return -;
return d[ex][ey][ez];
} int main() {
while(~scanf("%d %d %d",&X,&Y,&Z)) {
if(X == && Y == && Z == ) break;
for(int i = ;i < X;i++) {
for(int j = ;j < Y;j++) {
scanf("%s",maz[i][j]);
for(int k = ;k < Z;k++) {
if(maz[i][j][k] == 'S') {
sx = i;
sy = j;
sz = k;
} else if(maz[i][j][k] == 'E') {
ex = i;
ey = j;
ez = k;
}
}
}
} int res = bfs();
if(res == -) {
printf("Trapped!\n");
} else {
printf("Escaped in %d minute(s).\n",res);
}
}
return ;
}

poj 2251 Dungeon Master的更多相关文章

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

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

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

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

  3. 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 ...

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

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

  5. BFS POJ 2251 Dungeon Master

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

  6. POJ 2251 Dungeon Master (三维BFS)

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

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

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

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

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

  9. POJ 2251 Dungeon Master(多层地图找最短路 经典bfs,6个方向)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48380   Accepted: 18252 ...

随机推荐

  1. 创业方向:O2O及移动社交 from 沈博阳

    十个最大的互联网公司,六个在美国,四个在中国 中国创业的特殊 市场巨大self-contained,做足中国市场就很够 ... ... 监管   领导力,人的要求 之前成功带领过团队 有海外的工作经历 ...

  2. Pig语言基础-【持续更新中】

      ***本文参考了Pig官方文档以及已有的一些博客,并加上了自己的一些知识性的理解.目前正在持续更新中.***   Pig作为一种处理大规模数据的高级查询语言,底层是转换成MapReduce实现的, ...

  3. pointers on c (day 1,chapter3)

    第3章 数据 c中,仅有4中基本数据类型——整型.浮点型.指针和聚合类型(如数组和结构等). 整型:字符.短整型和长整型,它们都分为有符号(signed)和无符号(unsigned). short i ...

  4. [转]Nodejs基础中间件Connect

    Nodejs基础中间件Connect 从零开始nodejs系列文章,将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的引擎,是目前速度最快的J ...

  5. JSHint Options 翻译

    Enforcing options When set to true, these options will make JSHint produce more warnings about your ...

  6. Javascript for循环指定锚点跳转

    在某些使用多层嵌套for循环的场合里 会用到break和continue来中途跳转循环 break是跳出整个循环 continue是跳出当前循环,继续下次循环 而多层for循环嵌套里使用这两个关键字默 ...

  7. html()、text()、val()、innerHTML、value()的区分

    以上的方法可用于一般的html标签(div)与input中分别进行讨论 1.html(): jQuery方法,用于一般标签中,可读写,可以获得写入html标签. 2.text(): jQuery方法, ...

  8. ArcEngine 岛状多边形内部环的获取

    ArcEngine岛状多边形获取其内部环 查阅了帮助文档相关接口,内部环的获方法get_InteriorRingBag() 需要外部环作为参数.而外部环可以直接通过ExteriorRingBag属性获 ...

  9. Lua字符串库

    1. 基础字符串函数:    字符串库中有一些函数非常简单,如:    1). string.len(s) 返回字符串s的长度:    2). string.rep(s,n) 返回字符串s重复n次的结 ...

  10. 重置dns

    flusdns