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 ...
随机推荐
- 关于react打包之后静态资源加载错误的问题
之前在打包react项目时发现一些问题,打包出来后我的一部分png图标加载不出来,开发者模式发现他们的路径中莫名其妙混入了我在react-router路由中使用<Browserrouter> ...
- 为何D3D11的几个矩阵需要转置?
在学习D3D11的时候遇到一个问题,事情是这样的: D3D11引入了常量缓存(const buffer)用来实现数据的高速传输,这块儿buffer是CPU Only Write,GPU Only Re ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力)
The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门:https://nanti.jisuanke.com/ ...
- Jquery xhr2跨域
相关享目托管在github: https://github.com/devgis/CSharpCodes
- css3条件判断_@supports的用法 以及 Window.CSS.supports()的使用
为了判断浏览器是否支持css3的一些新属性样式,当不兼容该样式的时候,我们可以更优雅的降级处理.这就需要使用到css3的条件判断功能:在css中支持@supports标记.或者在js中使用CSS.su ...
- VRChat之blender教程
推荐先看:VRChat模型制作及上传总篇(包含总流程和所需插件):https://www.cnblogs.com/raitorei/p/12015876.html 0.设置中文,安装cat插件 注意 ...
- DEVOPS技术实践_12:创建持续集成的管道
持续集成不仅包含了Jenkins或者相关其它的CI工具,也包含了包含代码如何控制,采用的什么分支策略等.不同的组织可能采用不同的类型的策略来完成CI,策略类型和项目的类型的有很大的关系. 一 分支策略 ...
- 关于有向图走“无限次”后求概率/期望的口胡/【题解】HNCPC2019H 有向图
关于有向图走"无限次"后求概率/期望的口胡/[题解]HNCPC2019H 有向图 全是口胡 假了不管 讨论的都是图\(G=(V,E),|V|=n,|E|=m\)上的情况 " ...
- 洛谷$P2150\ [NOI2015]$寿司晚宴 $dp$
正解:$dp$ 解题报告: 传送门$QwQ$. 遇事不决写$dp$($bushi$.讲道理这题一看就感觉除了$dp$也没啥很好的算法能做了,于是考虑$dp$呗 先看部分分?$30pts$发现质因数个数 ...
- 洛谷$P4768\ [NOI2018]$归程 $kruscal$重构树
正解:$kruscal$重构树 解题报告: 传送门$QwQ$ 语文不好选手没有人权$TT$连题目都看不懂真的要哭了$kk$ 所以先放个题目大意?就说给定一个$n$个点,$m$条边的图,每条边有长度和海 ...