Dungeon Master(三维bfs)
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<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
char Map[][][];
int vis[][][];
struct node
{
int x,y,z;
int cnt;
};
using namespace std;
int sx,sy,sz;
int ex,ey,ez;
int dir[][]={{,,},{,,-},{-,,},{,,},{,,},{,-,}};
int s;
bool check(int x,int y,int z)
{
if((Map[z][x][y]=='.'||Map[z][x][y]=='E')&&vis[z][x][y]==)
{
return true;
}
else
{
return false;
}
}
bool bfs()
{
node start;
start.x=sx;
start.y=sy;
start.z=sz;
start.cnt=;
queue<node>q;
q.push(start);
vis[sz][sx][sy]=;
while(!q.empty())
{
node now=q.front();
q.pop();
//printf("%d %d %d\n",now.z,now.x,now.y);
if(now.z==ez&&now.x==ex&&now.y==ey)
{
s=now.cnt;
return true;
}
for(int t=;t<;t++)
{
node next;
next.x=now.x+dir[t][];
next.y=now.y+dir[t][];
next.z=now.z+dir[t][];
next.cnt=now.cnt+;
if(check(next.x,next.y,next.z))
{
vis[next.z][next.x][next.y]=;
q.push(next);
} }
}
return false;
}
int main()
{
int L,R,C;
while(scanf("%d%d%d",&L,&R,&C)!=EOF)
{
memset(vis,,sizeof(vis));
if(L==&&R==&&C==)
{
break;
}
s=;
for(int t=;t<L;t++)
{
for(int j=;j<R;j++)
{
scanf("%s",Map[t][j]);
}
}
for(int t=;t<L;t++)
{
for(int j=;j<R;j++)
{
for(int k=;k<C;k++)
{
if(Map[t][j][k]=='S')
{
sx=j;
sy=k;
sz=t;
}
if(Map[t][j][k]=='E')
{
ex=j;
ey=k;
ez=t;
}
}
}
} if(bfs())
printf("Escaped in %d minute(s).\n",s);
else
{
printf("Trapped!\n");
}
} return ;
}
Dungeon Master(三维bfs)的更多相关文章
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- ZOJ 1940 Dungeon Master 三维BFS
Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- UVa532 Dungeon Master 三维迷宫
学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #i ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- 棋盘问题(DFS)& Dungeon Master (BFS)
1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...
- Dungeon Master (简单BFS)
Problem Description You are trapped in a 3D dungeon and need to find the quickest way out! The dunge ...
- POJ 2252 Dungeon Master 三维水bfs
题目: http://poj.org/problem?id=2251 #include <stdio.h> #include <string.h> #include <q ...
随机推荐
- requests入门实践02_下载斗图拉最新表情包
新版本移步:https://www.cnblogs.com/zy7y/p/13376228.html 下载斗图拉最新表情包 要爬取的目标所在网址:http://www.doutula.com/phot ...
- 深度学习论文翻译解析(十二):Fast R-CNN
论文标题:Fast R-CNN 论文作者:Ross Girshick 论文地址:https://www.cv-foundation.org/openaccess/content_iccv_2015/p ...
- 全球疫情爬取APP版
全球疫情统计APP图表展示: 将该任务分解成三部分来逐个实现: ①爬取全球的疫情数据存储到云服务器的MySQL上 ②在web项目里添加一个servlet,通过参数的传递得到对应的json数据 ③设计A ...
- 学习Hibernate5这一篇就够了
配套资料,免费下载 链接:https://pan.baidu.com/s/1i_RXtOyN1e4MMph6V7ZF-g 提取码:8dw6 复制这段内容后打开百度网盘手机App,操作更方便哦 第一章 ...
- drop blocks
- 伸展树(Splay)学习笔记
二叉排序树能够支持多种动态集合操作,它可以被用来表示有序集合,建立索引或优先队列等.因此,在信息学竞赛中,二叉排序树应用非常广泛. 作用于二叉排序树上的基本操作,其时间复杂度均与树的高度成正比,对于一 ...
- 【小白学AI】XGBoost 推导详解与牛顿法
文章转自公众号[机器学习炼丹术],关注回复"炼丹"即可获得海量免费学习资料哦! 目录 1 作者前言 2 树模型概述 3 XGB vs GBDT 3.1 区别1:自带正则项 3.2 ...
- 分析现有 WPF / Windows Forms 程序能否顺利迁移到 .NET Core 3.0
本文转自 https://blog.csdn.net/WPwalter/article/details/82859449 使用 .NET Core 3.0 Desktop API Analyzer 分 ...
- C#LeetCode刷题之#350-两个数组的交集 II(Intersection of Two Arrays II)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4044 访问. 给定两个数组,编写一个函数来计算它们的交集. 输入 ...
- 漏洞重温之XSS(中)
漏洞重温之XSS(中) XSS挑战之旅 level8-level13 level8 第八关开局,发现button从搜索变成了友情链接,发现该页面情况跟前面不同,先右键查看代码,再进行尝试. 上测试代码 ...