Dungeon Master (广搜)
问题描述:
Is an escape possible? If yes, how long will it take?
Input
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
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 (广搜)的更多相关文章
- POJ 2251 Dungeon Master(广搜,三维,简单)
题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- 1253 Dungeon Master
题目链接: http://noi.openjudge.cn/ch0205/1253/ http://poj.org/problem?id=2251 总时间限制: 1000ms 内存限制: 65536 ...
- 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 ...
- 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 ...
- 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 ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5652(二分+广搜)
题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...
- nyoj 613 免费馅饼 广搜
免费馅饼 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy ...
随机推荐
- CodeForces - 1013B And 与运算暴力
题目链接: https://vjudge.net/problem/1735275/origin 基本思路: 本题思路比较简单,首先,我们知道 a & x = b, b & x = b; ...
- 2017-10-22—发光二极管
LED与 LD的差别在工作原理上的差别:LED是利用注入有源区的载流子自发辐射复合发光,而LD是受激辐射复合发光.在结构上的差别:LD有光学谐振腔,使产生的光子在腔内振荡放大,LED没有谐振腔.性能上 ...
- Linux中Hadoop的环境搭建
一:下载安装 Hadoop 1.1:下载指定的Hadoop 1.2:通过XFTP把文件上传到master电脑bigData目录下 1.3:解压hadoop压缩文件 tar -xvf hadoop-2. ...
- [POJ1723]SOLDIERS(中位数)
题意 给出n个点的坐标,它们只能往上.下.左.右一格一格地移动,求使其移动至水平线上的最小步数. 思路 转载 先易后难,对于纵向的问题,我们推个公式,,这个很容易看出是货仓选址问题,k取y[i]的中位 ...
- 小甲鱼Python第十九讲课后习题
笔记: 1.内嵌函数:函数内部新创建另一个函数 2.闭包:函数式编程的重要语法,如果在一个内部函数里,对外部作用域(但不是在全局作用域的变量)进行引用,那么内部函数就会被认为是闭包. 3.nonloc ...
- (75)Wangdao.com第十三天_JavaScript 包装对象
包装对象 所谓“包装对象”,就是分别与数值.字符串.布尔值相对应的Number.String.Boolean三个原生对象 这三个原生对象可以把原始类型的值变成(包装成)对象 var v1 = new ...
- winform 利用Http向服务器上传与下载文件
利用在服务器端的IIS,布置“请求处理映射”.从而处理,本地发出Post请求.Url指向web网站所在路径的请求映射.由映射代码实现服务器保存文件. winform里面使用,WebClient的对象, ...
- amoeba实现读写分离
amoeba的运行环境依靠java的jdk: 下面执行amoeba的安装不走 # mkdir /usr/local/src/amoeba 上传文件:amoeba-mysql-binary-2.2.0. ...
- PrintService类打印
系统打印服务框架代码位于android.printservice包中.系统并没有实现具体打印功能,需要打印机厂商制作插件接入系统打印服务之后,自行实现 主要类: PrintDocument:表示待打印 ...
- 使用ngnix做服务器的负载均衡
(1) 进程数与每个进程的最大连接数: nginx进程数,建议设置为等于CPU总核心数 单个进程最大连接数,那么该服务器的最大连接数=连接数*进程数 (2) Ngnix的基本配置 监听端口一般都为h ...