poj 2251 Dungeon Master
http://poj.org/problem?id=2251
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 18773 | Accepted: 7285 |
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! 分析:
典型的三维广搜。 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的更多相关文章
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- 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)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- 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(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
- POJ 2251 Dungeon Master(多层地图找最短路 经典bfs,6个方向)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48380 Accepted: 18252 ...
随机推荐
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
A. Toda 2 按题意模拟即可. #include <bits/stdc++.h> using namespace std ; typedef pair < int , int ...
- Android调用默认浏览器打开指定Url
业务员有需求要将一个wap站在手机上以App的形式打开,还不要嵌套WebView,只能以浏览器打开.查了点资料,就有了下面这货. package com.gzz.whyinzi; import and ...
- js学习
2014-02-21 var p=function(){}(); //表示定义一个变量P,变量后面的函数为返回值 var p = function(){return 'abc';}(); alert( ...
- 关于history的Linux命令行
1.使用 HISTTIMEFORMAT 显示时间戳当你从命令行执行 history 命令后,通常只会显示已执行命令的序号和命令本身.如果你想要查看命令历史的时间戳,那么可以执行: # export H ...
- dede判断当前文章
<li><a href="/info/info3.html" class=s >企业文化 </a></li><li> ...
- opencv的问题
opencv中图像文件格式是BRG的顺序 而QImage是RGB形式 H:色彩 S:深浅 s=0 只有灰度 V:明暗
- 【手把手教你Maven】构建过程
Maven是一款进行 依赖管理.项目构建.信息管理 为一体的工具. 它不像Make具有复杂的命令.也不像Ant需要手动编写大量的重复代码就能进行项目的构建: 还能提供强大的依赖库管理,避免jar包混乱 ...
- Unity学习疑问记录之保卫伦敦塔学习体会
1.生成的prefab如果要产生反向: Instantiate(Rocket, rocketPosition.position, Quaternion.Euler(new Vector3(0,0,18 ...
- IOS网络第四天 -网络文件上传(0923略)
01-NSURLSession02-断点续传 02-文件上传01-基本的上传 03-文件上传03-代码封装 04-文件上传04-获得MIMEType.mp4 05-文件的压缩和解压缩.mp4 06-压 ...
- linux文件数相关命令
查看系统目前打开的文件数命令#cat /proc/slabinfo | grep ip_conn | grep -v ip_conntrack_expect | awk '{print $2}' 查看 ...