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. 服务端的GET、POST请求

    一.HttpClient方式,程序集 System.Net.Http.dll GET: HttpClient httpClient = new HttpClient(); string result ...

  2. Android服务(Service)研究

    Service是android四大组件之一,没有用户界面,一直在后台运行. 为什么使用Service启动新线程执行耗时任务,而不直接在Activity中启动一个子线程处理? 1.Activity会被用 ...

  3. Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  4. *HDU3357 判环

    Stock Chase Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. android中的回调简单认识

    首先说一下最抽象的形式--2个类,A类和B类.A类含有1个接口.1个接口变量.(可能含有)1个为接口变量赋值的方法以及1个会使用接口变量的"地方";B类实现A中的接口,(可能)含有 ...

  6. 不小心删除了sysWOW64下的webio.dll

    weibo的桌面客户端留了一个服务,在syswow64目录下留了个exe文件,看着旁边好像还有个weibo.dll,就把试着也删除了,但是删除不掉,我就进安全模式删除了(f8在Windows的启动界面 ...

  7. eclipse java项目中明明引入了jar包 为什么项目启动的时候不能找到jar包 项目中已经 引入了 com.branchitech.app 包 ,但时tomcat启动的时候还是报错? java.lang.ClassNotFoundException: com.branchitech.app.startup.AppStartupContextListener java.lang.ClassN

    eclipse java项目中明明引入了jar包 为什么项目启动的时候不能找到jar包 项目中已经 引入了 com.branchitech.app 包 ,但时tomcat启动的时候还是报错?java. ...

  8. PhpStorm 10 破解方法

    最新版PhpStorm 10正式版改进了PHP 7支持,改进代码完成功能. PhpStorm 是最好的PHP开发工具,使用它进行PHP开发将会让你感觉到编程的乐趣. 快乐无极终于从oschina看到了 ...

  9. Mybatis缓存处理机制

    一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 一级缓存: 基于PerpetualCache 的 HashMap本地缓存,其存储作用域为 Se ...

  10. mysql5.1升级到mysql5.6

    这么大跨度的升级,本身不推荐.升级应该是循序渐进的,以防止不兼容.如果确实要这么做,你先要确保你的客户端管理工具要能兼容,比如phpmyadmin,此次升级依然存在一个问题,mysql server和 ...