描述

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的更多相关文章

  1. 1253 Dungeon Master

    题目链接: http://noi.openjudge.cn/ch0205/1253/ http://poj.org/problem?id=2251 总时间限制: 1000ms  内存限制: 65536 ...

  2. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  3. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  4. Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...

  5. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  6. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

  7. Dungeon Master poj 2251 dfs

    Language: Default Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16855 ...

  8. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  9. BFS POJ2251 Dungeon Master

    B - Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. javascript修改css样式表

    //创建var sheet=document.createElement('style');document.bodt.appendChild(sheet);sheet.styleSheet.cssT ...

  2. 2018-2-13-win10-UWP-九幽数据分析

    title author date CreateTime categories win10 UWP 九幽数据分析 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 1 ...

  3. 2018-10-23-WPF-使用-Pandoc-把-Markdown-转-Docx

    title author date CreateTime categories WPF 使用 Pandoc 把 Markdown 转 Docx lindexi 2018-10-23 11:35:47 ...

  4. P4556 [Vani有约会]雨天的尾巴 (线段树合并)

    P4556 [Vani有约会]雨天的尾巴 题意: 首先村落里的一共有n座房屋,并形成一个树状结构.然后救济粮分m次发放,每次选择两个房屋(x,y),然后对于x到y的路径上(含x和y)每座房子里发放一袋 ...

  5. CS224n: Natural Language Processing学习准备

    cs224n 斯坦福网址,里面包含讲课视频,ppt,代码,学习完后做一个问答系统 http://web.stanford.edu/class/cs224n/index.html 下载anaconda, ...

  6. python3中map函数

    map函数是Python里面比较重要的函数 map函数后面必须接的是序列(元组/列表/字符串) 在python2中执行一些语句 >>> map(str,[1,2,3,4]) ['1' ...

  7. 两个int数组对比,返回差异数据

    public static int[] DataDifference(int[] more, int[] few) { //差异Id var sbuNoItapSessionId = new int[ ...

  8. 【一起学源码-微服务】Ribbon 源码二:通过Debug找出Ribbon初始化流程及ILoadBalancer原理分析

    前言 前情回顾 上一讲讲了Ribbon的基础知识,通过一个简单的demo看了下Ribbon的负载均衡,我们在RestTemplate上加了@LoadBalanced注解后,就能够自动的负载均衡了. 本 ...

  9. Cent OS防火墙配置端口开放

    CentOS 6内置的防火墙为iptables,Cent OS7,内置的防火墙则是firewalld iptables 防火墙设置 1.打开/关闭/重启防火墙 #开启防火墙(重启后永久生效): chk ...

  10. 怎样使我们的用户不再抵触填写Form表单?

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://blog.bitsrc.io/8-tips-for-an-awesome-sign ...