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. Android APK反编译就这么简单 详解

    在学习Android开发的过程你,你往往会去借鉴别人的应用是怎么开发的,那些漂亮的动画和精致的布局可能会让你爱不释手,作为一个开发者,你可能会很想知道这些效果界面是怎么去实现的,这时,你便可以对改应用 ...

  2. Git,GitHub以及GitLab的区别

    Git - 版本控制工具 Github - 一个网站,提供给用户空间创建git仓储,保存用户的一些数据文档或者代码等 GitLab - 基于Git的项目管理软件 Git分布式版本控制系统 Git是一款 ...

  3. Opencv读取图片像素值

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

  4. 优化mysql slave的同步速度

    测试环境:Red Hat Enterprise Linux Server release 6.3 (Santiago)Server version: 5.6.22-log MySQL Communit ...

  5. JAVA本地调用(JNI- java调用c)

    记录一下工作内容,对术语了解不多,暂且这样记着吧.  java调用c 一.写jni的步骤如下: 1.创建java类,定义接口函数,使用native修饰: 2.将java类编译成class: 3.将cl ...

  6. vscode安装设置go

    vscode安装设置go vscode安装go配置 1.下载最新的vscode: https://code.visualstudio.com/docs/?dv=win 2.下载go: https:// ...

  7. delphi android 录像

    delphi xe系列自带的控件都无法保存录像,经网友帮忙,昨天终于实现了录像功能(但有个问题是录像时无画面显示),程序主要使用了JMediaRecorder,MediaRecorder的使用方法可参 ...

  8. Android-Observer(内容观察者)

    内容提供者应用暴露的数据,是被多个其他应用访问(insert,update,delete,query),但如果L应用要查询(内容提供者应用暴露的数据),难道要开启子线程一直循环去查询 ? 答:开启子线 ...

  9. mysql中判断记录是否存在方法比较【转】

    把数据写入到数据库的时,常常会碰到先要检测要插入的记录是否存在,然后决定是否要写入. 我这里总结了判断记录是否存在的常用方法: sql语句:select count(*) from tablename ...

  10. wp8.1启动协议

    var uri = new Uri(string.Format(@"ms-windows-store:navigate?appid={0}", appid));商店根据appid跳 ...