POJ 2251 题解
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 27520 | Accepted: 10776 |
Description
Is an escape possible? If yes, how long will it take?
Input
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
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 "cstdio"
#include "fstream"
#include "sstream"
#include "cstring" using namespace std;
const int maxN = 3e4 + 1e2 ;
struct Queue { int x , y , z ; } ;
typedef long long QAQ ; int dx[ ] = { , - , , , , } ;
int dy[ ] = { , , , , - , } ;
int dz[ ] = { , , - , , , } ; int step[ maxN ] ;
Queue Q[ maxN ] ;
bool vis[ ][ ][ ] ;
char map[ ][ ][ ] ; int L , R , C ;
int start_x , start_y , start_z , des_x , des_y , des_z ;
//QAQ Ans ; void Init ( ) {
memset ( vis , false , sizeof ( vis ) ) ;
memset ( step , , sizeof ( step ) ) ;
} inline bool Check ( const int x_x , const int y_y , const int z_z ) {return ( x_x == des_x && y_y == des_y && z_z == des_z ) ? true : false ; }
int BFS ( ) {
int Head = , Tail = ;
Q[ Tail ].x = start_x ;
Q[ Tail ].y = start_y ;
Q[ Tail ].z = start_z ;
while ( Head <= Tail ) {
for ( int i= ; i< ; ++i ) {
int xx = Q[ Head ].x + dx[ i ] ;
int yy = Q[ Head ].y + dy[ i ] ;
int zz = Q[ Head ].z + dz[ i ] ;
if( !vis[ xx ][ yy ][ zz ] && ( map[ xx ][ yy ][ zz ] == '.' ) && xx >= && xx < L && yy >= && yy < R && zz >= && zz < C ) {
vis[ xx ][ yy ][ zz ] = true ;
Q[ ++Tail ].x = xx ;
Q[ Tail ].y = yy ;
Q[ Tail ].z = zz ;
step [ Tail ] = step[ Head ] + ;
if ( Check ( xx , yy , zz ) ) return step[ Tail ] ;
}
}
++ Head ;
}
return false ;
} void Scan ( ) {
for ( int i= ; i<L ; ++i , getchar ( ) ){
for ( int j= ; j<R ; ++j , getchar ( ) ){
for ( int k= ; k<C ; ++k ) {
map[ i ][ j ][ k ] = getchar ( ) ;
if ( map[ i ][ j ][ k ] == 'S' ) {
start_x = i ;
start_y = j ;
start_z = k ;
}
else if ( map[ i ][ j ][ k ] == 'E' ) {
map[ i ][ j ][ k ] = '.' ;
des_x = i ;
des_y = j ;
des_z = k ;
}
}
}
}
} inline void Print ( int temp ) {
if( temp ) printf ( "Escaped in %d minute(s).\n" , temp ) ;
else printf ( "Trapped!\n" ) ;
} int main ( ) {
while ( scanf ( "%d %d %d\n " , &L , &R , &C ) == && L && R && C ) {
Init ( ) ;
Scan ( );
Print ( BFS( ) ) ;
}
return ;
}
2016-10-19 18:50:40
(完)
POJ 2251 题解的更多相关文章
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- 【POJ 2251】Dungeon Master(bfs)
BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...
- 【BFS】POJ 2251
POJ 2251 Dungeon Master 题意:有一个地图,三维,走的方向是上下,左右,前后.问你最小步数从起始点走到出口. 思路:三维的BFS,就是多加一组状态,需要细心(不细心如我就找了半个 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- 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)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- [ACM训练] 算法初级 之 搜索算法 之 深度优先算法DFS (POJ 2251+2488+3083+3009+1321)
对于深度优先算法,第一个直观的想法是只要是要求输出最短情况的详细步骤的题目基本上都要使用深度优先来解决.比较常见的题目类型比如寻路等,可以结合相关的经典算法进行分析. 常用步骤: 第一道题目:Dung ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
随机推荐
- cURL函数
PHP的cURL函数是通过libcurl库与服务器使用各种类型的协议进行连接和通信的,curl目前支持HTTP GET .HTTP POST .HTTPS认证.FTP上传.HTTP基于表单的上传.co ...
- postgresql:pgadmin函数调试工具安装过程
通过安装第三方插件pldebugger,可实现在pgadmin客户端对函数设置断点.调试,具体过程如下: 1.下载pldebugger安装包:http://git.postgresql.org/git ...
- javascript数据结构与算法--链表
链表与数组的区别? 1. 定义: 数组又叫做顺序表,顺序表是在内存中开辟一段连续的空间来存储数据,数组可以处理一组数据类型相同的数据,但不允许动态定义数组的大小,即在使用数组之前必须确定数组的大小. ...
- PAT Mooc datastructure 6-1
Saving James Bond - Hard Version This time let us consider the situation in the movie "Live and ...
- 使用phpMyAdmin修改MySQL数据库root用户密码
点击顶部的“SQL”标签进入sql命令输入界面.输入以下命令: update mysql.user set password=PASSWORD('snsgou$123456') where user= ...
- Go - 路径、目录名、包名、文件名
先看一个示例: 1.目录结构 bin pkg src pk1 pk2 function1.go function2.go index.go 2.function1.go 文件内容: package p ...
- Spring中集合类型属性注入
我们都知道如何去注入普通属性的值,非常简单,那么我们如何去注入开发中常见的集合类型的属性了,别急,往下看. 这里将介绍如何给Map list set Array Properties 这些属性注入值. ...
- jython安装与配置
安装jython 0. 计算机中要安装jdk 1. 在官网www.jython.org上找到下载页面,然后下载jython-installe 2. 在cmd.exe中运行java -jar jytho ...
- C#动态创建和动态使用程序集、类、方法、字段等
C#动态创建和动态使用程序集.类.方法.字段等 分类:技术交流 (3204) (3) 首先需要知道动态创建这些类型是使用的一些什么技术呢?其实只要相关动态加载程序集呀,类呀,都是使用反射,那么动 ...
- Magento 创建新的数据实体 model 、 resource 和 collection 文件
一.创建model文件 class Bestbuy_PrepaidCard_Model_Used extends Mage_Core_Model_Abstract { protected ...