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 ...
随机推荐
- 牛客多校第三场 F Planting Trees
牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...
- Python_全局变量的定义
1.在my套件下新建一个关键字systemkey并进行脚本的编写:创建一个${var1}变量,并赋值为aaaaaaaaaa Set Global Variable ${var1} ...
- 第二阶段:4.商业需求文档MRD:3.PRD-页面结构图
这也是功能结构以及优先级 这是页面层级 页面结构图 再细分某一个频道或者子页面 层层细分 用mind做的页面结构图 里面也包含了功能
- Javascript事件系统
本文内容 事件基础 事件监听方式 事件默认行为 事件冒泡与事件捕获 事件绑定与事件委托 事件基础 注意:本文不会深入探究Javascript的事件循环. 提到事件,相信每位Javascript开发者都 ...
- windows 8.0 mysql 修改root 密码
Mysql 忘记root密码和修改root密码的解决方法(小结) 一.以下是Windows操作系统的操作步骤: 1. 关闭正在运行的MySQL服务-->net stop mysql 2. 打开D ...
- 洛谷$P2523\ [HAOI2011]\ Problem\ c$ $dp$
正解:$dp$ 解题报告: 传送门$QwQ$ 首先港下不合法的情况.设$sum_i$表示$q\geq i$的人数,当且仅当$sum_i>n-i+1$时无解. 欧克然后考虑这题咋做$QwQ$. 一 ...
- 洛谷$P$2252 取石子游戏 博弈论
正解:博弈论 解题报告: 传送门! 威佐夫博弈板子昂$QwQ$ 关于这一类问题也有个结论,是说,先手必败的状态一定形如$(\left \lfloor i+\phi \right \rfloor,\le ...
- selenium模块的基本使用
一.selenium库与requests库的区别 - selenium请求库: - 本质上是一个自动化测试模块; ---> 主要用于测试 UI界面 - selenium除了可以做自动化测试,还可 ...
- 推荐中的多任务学习-YouTube视频推荐
本文将介绍Google发表在RecSys'19 的论文<Recommending What Video to Watch Next: A Multitask Ranking System> ...
- 二、Spring Cloud之注册中心 Eureka
前言 算是正式开始学习 spring cloud 的项目知识了,大概的知道Springcloud 是由众多的微服务组成的,所以我们现在一个一个的来学习吧. 注册中心,在微服务中算是核心了.所有的服务都 ...