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 ...
随机推荐
- HihoCoder1338 A Game (区间DP)
<题目链接> 题目大意: 两个人轮流从一个序列中取数,他们都面临同样的二选一决策:是拿走最左边的数,还是拿走最右边的数?问先手最多能够得到的分数是多少. 解题分析: 一道比较经典的DP,因 ...
- SpringBoot启动tomcat源码解读
一.SpringBoot自动拉起Tomcat 原文链接:http://www.studyshare.cn/blog-front/blog/details/1136 SpringBoot框架是当前比较流 ...
- 【java】-- 多线程快速入门
1.什么是进程?什么是线程?两者区别? 1.每个正在系统上运行的程序都是一个进程,每个进程包含一到多个线程,多线程处理就是允许一个进程中在同一时刻执行多个任务. 2.线程是一组指令的集合,或者是程序的 ...
- react + antd 实现打印功能(踩了不少坑)
最近在有网页打印需求,尝试了一下react的打印功能,遇到了不少的坑: 1.react本身有一些打印的组件,但都不好用,都是基于window.print(),但是window.print()如果直接打 ...
- ISP PIPLINE (附加1) Green Imbalance
1.什么是Green imbalance 芯片的Gr和Gb通道获取的能量或者是输出的数据不一致,造成这种情况的原因一方面是Gr,Gb通道的半导体制造工艺方面的差异,另一方面是microlens的存在, ...
- docker+ubuntu14.04+cuda7.0
参考链接: http://tleyden.github.io/blog/2014/10/25/docker-on-aws-gpu-ubuntu-14-dot-04-slash-cuda-6-dot-5 ...
- XVIII Open Cup named after E.V. Pankratiev. GP of Romania
A. Balance 不难发现确定第一行第一列后即可确定全部,列不等式单纯形求解线性规划即可. #include<cstdio> #include<algorithm> usi ...
- python的array初识
from array import array """ 'b' signed char int 1 'B' unsigned char int 1 'u' Py_UNIC ...
- 嵌入式linux内存越界定位和解决 (转)
https://blog.csdn.net/meejoy/article/details/41729585 https://blog.csdn.net/killmice/article/details ...
- centos6.8 编译安装lnmp php7.2 mysql5.6 nginx1.1.4
编译操作参考版,没有每一步详细操作,慎入 关闭selinux和防火墙 service iptables stop chkconfig iptables off vi /etc/selinux/conf ...