POJ-2251-Dungeon Master(3D迷宫,BFS)
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)的更多相关文章
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- POJ 2251 Dungeon Master【三维BFS模板】
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...
- poj 2251 Dungeon Master 3维bfs(水水)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21230 Accepted: 8261 D ...
- POJ 2251 Dungeon Master(三维空间bfs)
题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- 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 ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
随机推荐
- 关于iOS URL缓存机制原理解析
关于URL缓存机制中 利用request对象判断是否缓存 其实request是否相等的判断依据是URLString是否相等
- linux系统/proc/stat信息与top的cup信息的联系及区别
一. /proc 目录 Linux系统上的/proc目录是一种文件系统,即proc文件系统,与其它常见的文件系统不同的是,/proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以文 ...
- CSS中的元素分类
CSS中的元素分类 元素是文档结构的基础,在CSS中,每个元素生成了一个包含了元素内容的框(box,也译为"盒子").但是不同的元素显示的方式会有所不同,例如<div> ...
- ROS tf 编程指南
ROS (Robot Operating System, 机器人操作系统)是最知名的机器人操作系统,广泛应用于无人驾驶和机器人,tf(transforms,坐标系转换)是ROS下的一个常用的工具库.r ...
- jquery.validate.js客户端验证
参考:http://www.runoob.com/jquery/jquery-plugin-validate.html http://www.cnblogs.com/artech/archive/20 ...
- 一些命令可以帮您了解Linux 操作系统用户信息
1 显示上次登录的用户信息列表,包括(登录时间.退出时间.登录IP): [sywu@wusuyuan ~]$ last root pts/1 192.168.1.3 Wed Aug 27 22:08 ...
- jquery中html()、text()、val()的区别
(2013-03-26 10:49:16) 转载▼ 分类: jquery .html()用为读取和修改元素的HTML标签 .text()用来读取或修改元素的纯文本内容 .val()用来读取或修改 ...
- 浅谈Oracle12c 数据库、用户、CDB与PDB之间的关系
名词介绍: 数据库:数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它产生 于距今六十多年前,随着信息技术和市场的发展,特别是二十世纪九十年代以 后,数据管理不再仅仅是存储和管理 ...
- 编写高质量代码改善C#程序的157个建议——建议120:为程序集指定强名称
建议120:为程序集指定强名称 虽然强名称在设计之初有防止被未授权的第三方软件非法执行程序的作用,但是因为它的破解方法并不难,所以现在强名称更多的意义在于它可以避免出现“DLL HELL”现象. “D ...
- Kernel-----EXPORT_SYMBOL使用
EXPORT_SYMBOL只出现在2.6内核中,在2.4内核默认的非static 函数和变量都会自动 导入到kernel 空间的, 都不用EXPORT_SYMBOL() 做标记的. 2.6就必须用EX ...