Dungeon Master

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 48111   Accepted: 18149

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!

三维迷宫,跟二维迷宫思路差不多;

#include <iostream>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std; char MAP[35][35][35];
bool visit[35][35][35];
int dir[6][3] =
{
{ 0, -1, 0}, //北
{ 0, 1, 0}, //南
{-1, 0, 0}, //西
{ 1, 0, 0}, //东
{ 0, 0, 1}, //上
{ 0, 0, -1}, //下
};
//int M[35][35][35];
int l, r, c;
struct MiGong
{
int x, y, z;
int way;
};
//MiGong dist[35][35][50];
MiGong v;
int k = 0; void BFS ( int x, int y, int z )
{
queue <MiGong> Q;
visit[x][y][z] = true;
v.x = x;
v.y = y;
v.z = z;
v.way = 0;
Q.push( v ); while( !Q.empty() )
{
v = Q.front();
Q.pop();
if( MAP[v.x][v.y][v.z] == 'E' )
break; MiGong now;
for( int i=0; i<6; i++ )
{
now.x = v.x + dir[i][0];
now.y = v.y + dir[i][1];
now.z = v.z + dir[i][2];
if( now.x >= 0 && now.y >= 0 && now.z >= 0 && now.x <= 30 && now.y <= 30 && now.z <= 30 ) if( !visit[now.x][now.y][now.z] && (MAP[now.x][now.y][now.z] == '.' || MAP[now.x][now.y][now.z] == 'E'))
{
//dist[now.x][now.y][now.z].way = dist[v.x][v.y][v.z].way + 1;
now.way = v.way + 1;
visit[now.x][now.y][now.z] = true;
Q.push( now );
}
} }
if( !v.way )
cout << "Trapped!" << endl;
else
cout << "Escaped in " << v.way <<" minute(s)." << endl;
//cout << v.way << endl; } int main()
{ int i, j, k; while(cin >> l >> r >> c && l && r && c )
{
memset( MAP, 0, sizeof(MAP));
memset( visit, 0, sizeof(visit));
int x = -1, y = -1, z = -1;
for( i=0; i<l; i++ )
for( j=0; j<r; j++ )
for( k=0; k<c; k++ )
{
cin >> MAP[i][j][k];
if( MAP[i][j][k] == 'S')
{
x = i;
y = j;
z = k;
}
}
BFS( x, y, z );
} return 0;
}

POJ-2251-Dungeon Master(3D迷宫,BFS)的更多相关文章

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

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

  2. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

  3. poj 2251 Dungeon Master 3维bfs(水水)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21230   Accepted: 8261 D ...

  4. POJ 2251 Dungeon Master(三维空间bfs)

    题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...

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

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

  6. BFS POJ 2251 Dungeon Master

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

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

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

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

  9. POJ 2251 Dungeon Master (三维BFS)

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

  10. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

随机推荐

  1. 第一话:IE中用DOM方法绑定事件

    工作比较忙,但是也一定要抽时间出来提升一下自己的基本功,只有技术实力到位,才能为公司和个人创造更多的价值.下面进入主题: IE中事件监听比较容易用到,但是由它所引出的一个关于this的问题,不得不着重 ...

  2. Openssl speed命令

    一.简介 speed命令用于测试库的性能 二.语法 openssl speed [md2] [mdc2] [md5] [hmac] [sha1] [sha256] [sha512] [whirlpoo ...

  3. fitting 方法的异常值过滤

    training = pd.DataFrame({'x':[3,6,9,15,300, 20,85]}).  原始数据training_fitting = pd.DataFrame({'x':[4,7 ...

  4. 添加字段modify

    ALTER TABLE tc_activity_turntable ADD `foot_pic` VARCHAR () NOT NULL DEFAULT '' COMMENT '底部图片';

  5. [Training Video - 4] [Groovy] Object equality and variable equality check

    def x=2 def y=3 if(x == y){ log.info "equal" }else{ log.info "not equal" // prin ...

  6. (转)TinyHttp源码剖析

    tinyhttpd 是一个不到 500 行的超轻量型 Http Server,用来学习非常不错,可以帮助我们真正理解服务器程序的本质. 看完所有源码,真的感觉有很大收获,无论是 unix 的编程,还是 ...

  7. HDU 6162 Ch’s gift (线段树+树链剖分)

    题意:给定上一棵树,每个树的结点有一个权值,有 m 个询问,每次询问 s, t ,  a, b,问你从 s 到 t 这条路上,权值在 a 和 b 之间的和.(闭区间). 析:很明显的树链剖分,但是要用 ...

  8. WordPaster-Drupal 7.34-CKEditor4x

    1.1. 集成到drupal 7x-ck4 插件下载:Drupal 7x, 1.1.1. 安装ckeditor4x 下载插件 说明:下载并解压 CKEditor4x插件:https://yunpan. ...

  9. Finding Memory Leaks with SAP Memory Analyzer

    Introduction There is a common understanding that a single snapshot of the java heap is not enough f ...

  10. java中关于Collection和Map相关的类&接口之间的关系

    上图(引用自)