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 ...
随机推荐
- vue-learning:19 - js - filters
filters 基本使用 仅限在插值{{}}和v-bind指令中使用 管道符|分隔 链式调用 传入参数 全局注册和局部注册 纯函数性质(不能使用this) 基本使用 我们看下之前用计算属性实现的例子, ...
- 一个vue管理系统的初步搭建总结
ps:目前这个项目只是有一个大致的框架,并没有做完 前期准备工作 前端构建工具:Visual Studio Code后端构建工具:IDEA数据库和服务器构建工具:WampServer (使用的是2.4 ...
- koa2实现简单的验证码
//首先引入svg-captcha,https://www.npmjs.com/package/svg-captcha const svgCaptcha = require('svg-captcha) ...
- 大数据vs计算机
大数据有两个方向,一个是偏计算机的,另一个是偏经济的.你学过Java,所以你可以偏将计算机 基础1. 读书<Introduction to Data Mining>,这本书很浅显易懂,没有 ...
- apache WEB服务器安装(包括虚拟主机)
一.apache下载编译安装 yum install apr apr-devel apr-util apr-util-devel gcc-c++ wget tar -y cd /usr/src wge ...
- Visual Studio 2019 编译.Net Core Console项目出现【MSB4018 The "CreateAppHost" task failed unexpectedly】 错误
需要测试一个小东东,使用Visual Studio 2019新建了一个.Net Core的Console程序,但是在编译的时候一直报错,死活编译不通过. 错误信息: Severity Code Des ...
- 【阿里云IoT+YF3300】10.快速开发188协议设备驱动
188协议的全称为CJ-T188-2004 <户用计量仪表数据传输技术条件>,是针对水表.燃气表.热量表和其他集中采集的一个国家行业标准协议. YFIOs就是YFSoft I/O Serv ...
- 面试官刁难:Java字符串可以引用传递吗?
老读者都知道了,六年前,我从苏州回到洛阳,抱着一幅"海归"的心态,投了不少简历,也"约谈"了不少面试官,但仅有两三个令我感到满意.其中有一位叫老马,至今还活在我 ...
- $Codeforces\ 522D\ Closest\ Equals$ 线段树
正解:线段树 解题报告: 传送门$QwQ$ 题目大意是说给定一个数列,然后有若干次询问,每次询问一个区间内相同数字之间距离最近是多少$QwQ$.如果不存在相同数字输出-1就成$QwQ$ 考虑先预处理出 ...
- 「Luogu P2278」[HNOI2003]操作系统 解题报告
题面 一道模拟题,模拟CPU的处理过程?!省选模拟题 思路: 模拟退火大法+优先队列乱搞 要注意的点 1.空闲时,CPU要处理进程 2.当队列中没有进程时,要先进行判断,然后访问 3.当优先级高的进程 ...