NOI2.5 1253:Dungeon Master
描述
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?
输入
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.
输出
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!
样例输入3 4 5
S. . . .
. ###.
. ##. .
###.#
#####
#####
##.##
##...
#####
#####
#.###
####E
1 3 3
S##
#E#
###
0 0 0
样例输出Escaped in 11 minute(s).
Trapped!
题目大意:
给定一个三维迷宫,给出起点(S)和终点(T),问从起点到终点要走几分钟(走一步一分钟),如果走不到终点,输出“Trapped!”
三维?!你提莫的在逗我?!二维已经够呛了,你给我来三维!!!
细想一下,也不是很难,广搜的话,多加两个方向的走法就可以了呀
队列再加一个来保存层数就行了呀
伪队列写法,一次AC
代码如下:
<span style="font-size:12px;BACKGROUND-COLOR: #ffff99">#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
char c[35];
int f[6]={1,-1,0,0,0,0},u[6]={0,0,-1,1,0,0},g[6]={0,0,0,0,-1,1},l,m,n,xz,yz,zz,num,nn;
bool v[35][35][35];
void find(int p,int q,int r)
{
int x=0,y=0,z=0,t=0,w=1,i;
int h[100001][4];
h[1][0]=p;
h[1][1]=q;
h[1][2]=r;
h[1][3]=0;
do
{
t++;
for(i=0;i<6;i++)
{
x=h[t][0]+f[i];
y=h[t][1]+u[i];
z=h[t][2]+g[i];
if(x>=0&&x<m&&y>=0&&y<n&&z>=0&&z<l&&!v[x][y][z])
{
w++;
h[w][0]=x;
h[w][1]=y;
h[w][2]=z;
h[w][3]=h[t][3]+1;
v[x][y][z]=1;
if(x==xz&&y==yz&&z==zz)
{
num=h[w][3];
return ;
}
}
}
}while(t<w);
}
int main()
{
int i,j,x,y,z;
scanf("%d%d%d",&l,&m,&n);
while(l&&m&&n)
{
num=0;
for(int o=0;o<l;o++)
for(i=0;i<m;i++)
{
scanf("%s",c);
for(j=0;j<=n;j++)
{
if(c[j]=='#')
v[i][j][o]=1;
if(c[j]=='S')
{
x=i;
y=j;
z=o;
v[i][j][o]=0;
}
if(c[j]=='E')
{
xz=i;
yz=j;
zz=o;
v[i][j][o]=0;
}
if(c[j]=='.')
v[i][j][o]=0;
}
}
v[x][y][z]=1;
find(x,y,z);
if(num)
printf("Escaped in %d minute(s).\n",num);
else
printf("Trapped!\n");
scanf("%d%d%d",&l,&m,&n);
}
}</span>
<span style="font-size:12px;BACKGROUND-COLOR: #ffff99"></span>
伪队列的方法很节约时间,即使三维也不会很耗时,所以,就这样啦
NOI2.5 1253:Dungeon Master的更多相关文章
- 1253 Dungeon Master
题目链接: http://noi.openjudge.cn/ch0205/1253/ http://poj.org/problem?id=2251 总时间限制: 1000ms 内存限制: 65536 ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- UVa532 Dungeon Master 三维迷宫
学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #i ...
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- BFS POJ2251 Dungeon Master
B - Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- 记一次奇葩事——html5可能不支持window.onscroll函数
只在html5里遇到,html4没事:拿出来聊聊,路过帮忙解答下!!! 不正常的 <!doctype html><html><head><meta chars ...
- TransactionDefinition接口中定义了七个事务传播行为
1.PROPAGATION_REQUIRED如果存在一个事务,则支持当前事务,如果没有事务则开启一个新的事务.使用spring声明式事务,spring使用AOP来支持声明式事务,会根据事务属性,自动在 ...
- <数论相关>逆元专题
逆元专题推荐这个blog:https://www.cnblogs.com/zjp-shadow/p/7773566.html 逆元问题应用的范围:处理分数模问题.例如求 42/4 + 42/8 + 3 ...
- wpf遮罩~~~(搬运过来的)
方便自己以后用,原文:https://blog.csdn.net/lwwl12/article/details/78472235 直接上代码 public partial class BaseWind ...
- ansible核心模块playbook介绍
ansible的playbook采用yaml语法,它简单地实现了json格式的事件描述.yaml之于json就像markdown之于html一样,极度简化了json的书写.在学习ansible pla ...
- HDU1556 Color the ball & 牛客 contest 135-I 区间 [差分标记]
一.差分标记介绍 差分标记用来解决针对区间(修改-查询)的问题,复杂度比线段树要更低.推荐这个博客. 例如,给数组中处于某个区间的数进行加减操作,然后查询某个位置上数的变化值. 二.HDU1556 C ...
- Gif动图压缩java版
简单说明下,如果不是压缩动图的话只用java本身的包足够实现压缩和截取图片了,为了能够压缩gif动图,这里引用了两个文件 AnimatedGifEncoder 和 GifDecoder, 先用Deco ...
- 前端Tips#2 - 将 arguments 转换成Array的最佳实践
本文同步自 JSCON简时空 - 技术博客,点击阅读 视频讲解 文字讲解 1.先讲结论 有很多种方式将 arguments 转换成数组,那么哪一种方式是最优的? 为节约大伙儿的时间,这里先说一下结论: ...
- Linux中 ps命令的参数讲解
Linux命令ps: (Process Status的缩写)该命令常常用来用来列出系统中当前运行的进程.ps是显示瞬间进程的状态,并不动态连续:如果想对进程进行实时监控应该用top命令 -a 显示所有 ...
- Synchronized解析——如果你愿意一层一层剥开我的心
前言 synchronized,是解决并发情况下数据同步访问问题的一把利刃.那么synchronized的底层原理是什么呢?下面我们来一层一层剥开它的心,就像剥洋葱一样,看个究竟. Synchroni ...