• 问题描述:

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?

Input

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.

Output

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!

Sample Input

3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0

Sample Output

Escaped in 11 minute(s).
Trapped!
  • 解题思路:

用三维数组来存地图,然后用广度优先搜索即可。
  • 代码:

#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
using namespace std;
char a[][][];
int l,r,c;
int next[][]={{,,},{-,,},{,,},{,-,},{,,},{,,-}};
struct node
{
int x;
int y;
int z;
int step;
}s,e,now,net; int bfs()
{
queue<node> q;
q.push(s);
while(q.size())
{
now=q.front();
if(now.x==e.x&&now.y==e.y&&now.z==e.z)
return now.step;
for(int i=;i<;i++)
{
net.x=now.x+next[i][];
net.y=now.y+next[i][];
net.z=now.z+next[i][];
if(net.x>&&net.x<=l&&net.y>&&net.y<=r&&net.z>&&net.z<=c&&a[net.x][net.y][net.z]!='#')
{
a[net.x][net.y][net.z]='#';
net.step=now.step+;
q.push(net);
}
}
q.pop();
}
return -;
} int main()
{
while(~scanf("%d%d%d",&l,&r,&c))
{
if(l==&&r==&&c==)break;
for(int i=;i<=l;i++)
{
for(int j=;j<=r;j++)
{
for(int k=;k<=c;k++)
{
scanf(" %c",&a[i][j][k]);
if(a[i][j][k]=='S')
{
s.x=i;
s.y=j;
s.z=k;
s.step=;
}
if(a[i][j][k]=='E')
{
e.x=i;
e.y=j;
e.z=k;
}
}
}
}
int ans=bfs();
if(ans==-)printf("Trapped!\n");
else printf("Escaped in %d minute(s).\n",ans);
}
return ;
}

Dungeon Master (广搜)的更多相关文章

  1. POJ 2251 Dungeon Master(广搜,三维,简单)

    题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...

  2. poj 2251 Dungeon Master

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

  3. 1253 Dungeon Master

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

  4. 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 ...

  5. POJ - 2251 Dungeon Master(搜索)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  6. POJ - 2251 Dungeon Master (搜索)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

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

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

  8. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  9. HDU 5652(二分+广搜)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...

  10. nyoj 613 免费馅饼 广搜

    免费馅饼 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy ...

随机推荐

  1. h5怎么做分享到QQ 、朋友圈、微信 、微博等功能

    微信已经成为我们日常聊天联系基本的必备工具,所以小菜我首先介绍一下如何调用微信的分享功能.其实除了可以在微信上分享到朋友圈和发送给好友,微信的分享接口还提供了分享到QQ和分享到腾讯微博等,就是在页面的 ...

  2. c#一步一步实现ORM(二)

    c#一步一步实现ORM(二) 上一篇描述了简单的思路,这一片我们来稍微细化一下 1插入的时候忽略某些字段 public int Insert<T>(T o, params string[] ...

  3. Linux中Buffer和Cache的区别

    1. Cache:缓存区,是高速缓存,是位于CPU和主内存之间的容量较小但速度很快的存储器,因为CPU的速度远远高于主内存的速度,CPU从内存中读取数据需等待很长的时间,而  Cache保存着CPU刚 ...

  4. 如何设计一个restful风格的API

    1.API接口应该尽量兼容之前的版本,在URL上应保留版本号,并同时兼容多个版本 2.每一个URI代表一个资源 3.请求方式要与http请求方式一致,GET(获取),POST(新增),PUT(更新全部 ...

  5. ECMA Script 6_symbol(symbol.iterator) 新接口_iterator接口

    iterator 接口 只要部署了 iterator 接口 symbol(symbol.iterator), 则可以进行 for...of  遍历

  6. Go语言基础之time包

    Go语言基础之time包 时间和日期是我们编程中经常会用到的,本文主要介绍了Go语言内置的time包的基本用法. Go语言中导入包 Go语言中使用import关键字导入包,包的名字使用双引号(”)包裹 ...

  7. winform 利用Http向服务器上传与下载文件

    利用在服务器端的IIS,布置“请求处理映射”.从而处理,本地发出Post请求.Url指向web网站所在路径的请求映射.由映射代码实现服务器保存文件. winform里面使用,WebClient的对象, ...

  8. 使用C#.NET列举组合数前N项和

    列举如下列所示的组合数前N项和,代码如下(递归方法里注意去重): static void Main(string[] args) { List<).ToList(); File.AppendAl ...

  9. nvwgf2umx.dll 显卡崩溃问题尝试修复

    问题背景 游戏上线之后,搜集到的奔溃列表里面列表存在大量的显卡驱动异常崩溃,window在vista之后,将显卡驱动模型从Xpdm改为了WDDM. WDDM的说明详见百度百科,其中最主要的变更如下: ...

  10. Git branch && Git checkout常见用法

    https://www.cnblogs.com/qianqiannian/p/6011404.html git branch 和 git checkout经常在一起使用,所以在此将它们合在一起 1.G ...