E - Dungeon Master BFS
[NWUACM]
你被困在一个三维的空间中,现在要寻找最短路径逃生!
空间由立方体单位构成
你每次向上下前后左右移动一个单位需要一分钟
你不能对角线移动并且四周封闭
是否存在逃出生天的可能性?如果存在,则需要多少时间?
Input - 输入
输入第一行是一个数表示空间的数量。
每个空间的描述的第一行为L,R和C(皆不超过30)。
L表示空间的高度。
R和C分别表示每层空间的行与列的大小。
随后L层地牢,每层R行,每行C个字符。
每个字符表示空间的一个单元。'#'表示不可通过单元,'.'表示空白单元。你的起始位置在'S',出口为'E'。
每层空间后都有一个空行。L,R和C均为0时输入结束。
Output - 输出
每个空间对应一行输出。
如果可以逃生,则输出如下
Escaped in x minute(s).
x为最短脱离时间。
如果无法逃生,则输出如下
Trapped!
Sample Input - 输入样例
3 4 5
S....
.###.
.##..
###.#
#####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0
Sample Output - 输出样例
Escaped in 11 minute(s).
Trapped! 思路:这个题目就是6个方向的BFS把 方向设定好,,找到起点找到终点,然后BFS吧
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstdio>
#include<cstring>
#define N 33
//int base[6][3] = { {-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1} };
using namespace std;
int l,n,m;
char arr[N][N][N];
int mark[N][N][N];
int sa,sb,sc;
int ea,eb,ec;
struct stu{
int a,b,c;//坐标
int s;//距离
}e1,e2,e3;
int base[][] = { {-,,},{,,},{,-,},{,,},{,,-},{,,} };//6个方向
void BFS(){
memset(mark,,sizeof(mark));
queue<stu >s;
e1.a=sa,e1.b=sb,e1.c=sc;
e1.s=;
s.push(e1);
mark[sa][sb][sc]=; int ans=-;
while(s.size()){
e2=s.front();
s.pop();
if(e2.a==ea && e2.b==eb && e2.c==ec)//判断是否到达了终点
{
ans=e2.s;
break;
}
for(int i=;i<;i++){
e3.a=e2.a+base[i][];
e3.b=e2.b+base[i][];
e3.c=e2.c+base[i][];
if((e3.a>= ) && (e3.a < l) && (e3.b >= ) && (e3.b < n) && (e3.c >= ) && (e3.c < m)
&& (!mark[e3.a][e3.b][e3.c]) && (arr[e3.a][e3.b][e3.c] == '.' || arr[e3.a][e3.b][e3.c] == 'E'))
{
e3.s=e2.s+;
mark[e3.a][e3.b][e3.c]=;
s.push(e3);
} }
}
if(ans==-){
cout<<"Trapped!"<<endl;
}
else {
printf("Escaped in %d minute(s).\n",ans);
}
} int main()
{
while(cin>>l>>n>>m){
if(n==&&m==&&l==)
break;
for(int i=;i<l;i++){
for(int j=;j<n;j++){
scanf("%s",&arr[i][j]);
}
}
for(int i=;i<l;i++){
for(int j=;j<n;j++){
for(int k=;k<m;k++){
if(arr[i][j][k]=='S')
{
sa=i;
sb=j;
sc=k;
}
else if(arr[i][j][k]=='E'){
ea=i;
eb=j;
ec=k;
}
}
}
}
BFS();
}
return ;
}
E - Dungeon Master BFS的更多相关文章
- hdu 2251 Dungeon Master bfs
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17555 Accepted: 6835 D ...
- POJ2251 Dungeon Master —— BFS
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- Dungeon Master bfs
time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u POJ 2251 Descriptio ...
- poj 2251 Dungeon Master (BFS 三维)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- [poj] Dungeon Master bfs
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- poj 2251 Dungeon Master( bfs )
题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A, 上代码 #include <iostream> #include<cst ...
- POJ 2251 Dungeon Master (BFS最短路)
三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...
- POJ2251 Dungeon Master(bfs)
题目链接. 题目大意: 三维迷宫,搜索从s到e的最小步骤数. 分析: #include <iostream> #include <cstdio> #include <cs ...
- POJ 2251 Dungeon Master bfs 难度:0
http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...
随机推荐
- TensorFlow 趣题
checkpoint 文件夹 Tensorflow训练后的模型可以保存checkpoint文件,checkpoint文件是结构与权重分离的四个文件,便于训练. 1)checkpoint 文件 保存断点 ...
- [模板] dijkstra (堆优化)
复杂度O(mlogn) 输入起点s,可以得到从起点到各点的最短路距离数组dis[i] 过程: 1.初始化:清空标记数组,初始化距离数组设为inf,起点距离设为0,开优先队列,搜索起点 2.搜索:取出队 ...
- mysql系列--sql实现原理
count(*) MyISAM 引擎把⼀个表的总⾏数存在了磁盘上,因此执⾏ count(*) 的时候会直接返回这个数,效率很⾼:但是加了条件则不能快速返回⽽ InnoDB 引擎就麻烦了,它执⾏ cou ...
- sql MySQL5.7 安装 centos docker
MySQL5.7 安装 1 . 普通安装 # 准备工作 停止以前的数据库并删除配置文件 systemctl stop mysqld rpm -e mysql-community-server-5.7. ...
- TCP漫谈之keepalive和time_wait
TCP是一个有状态通讯协议,所谓的有状态是指通信过程中通信的双方各自维护连接的状态. 一.TCP keepalive 先简单回顾一下TCP连接建立和断开的整个过程.(这里主要考虑主流程,关于丢包.拥塞 ...
- python fabric 练习记录
https://blog.csdn.net/freeking101/article/details/81103945 fabric 域名
- 树莓派中Docker部署.Net Core 3.1 (一)
一.背景 受疫情影响,已经在家强制事假一个月了,除了刷简历外就是在家学习,闲来无事,最近买了几个树莓派4B的板子回来,准备用树莓派搭建个自动部署的平台和微服务示例,长话短说,节约时间,直接进入正题吧 ...
- 1047: 【入门】正整数N转换成一个二进制数
1047: [入门]正整数N转换成一个二进制数 时间限制: 1 Sec 内存限制: 16 MB 提交: 9786 解决: 6447 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 输入 ...
- raphael.js 使用指南
RaphaelJS是一个用JavaScript实现的强大的矢量图形库. (1)使用前准备,下载RaphaelJS,到官网下载. (2)在相应的HTML页面引入RaphaelJS,如下示例代码: < ...
- 为什么MySQL要用B+树?聊聊B+树与硬盘的前世今生【宇哥带你玩转MySQL 索引篇(二)】
为什么MySQL要用B+树?聊聊B+树与硬盘的前世今生 在上一节,我们聊到数据库为了让我们的查询加速,通过索引方式对数据进行冗余并排序,这样我们在使用时就可以在排好序的数据里进行快速的二分查找,使得查 ...