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 ...
随机推荐
- 在vscode中配置LeetCode插件,从此愉快地刷题
大家好,今早在B站看到up主的vscode里藏了leetcode插件,这才知道原来还有这款神器.但是没想到在用的时候遇到了一些麻烦,花了一点时间才解决.所以写这篇文章除了给大家安利这个好用的插件之外, ...
- 实例演示:如何简化生产中的Pod安全策略?
Pod安全策略对于强化K8S集群安全至关重要.本文将延续之前的文章继续深入介绍Pod安全策略. 首先,简单介绍了如何将Pod与Pod安全策略相关联,并使用RBAC来展示具体步骤.然后介绍如何在Ranc ...
- display:flex 简单记录
1.有写了 display:flex:这个就是 采用了 flex布局的 元素 这个元素可以 写 6个属性: flex-direction : row | column | row-reverse ...
- TensorFlow 训练好模型参数的保存和恢复代码
TensorFlow 训练好模型参数的保存和恢复代码,之前就在想模型不应该每次要个结果都要重新训练一遍吧,应该训练一次就可以一直使用吧. TensorFlow 提供了 Saver 类,可以进行保存和恢 ...
- python3读取excel实战
'''参数化'''import xlrd,xlwt,jsonfrom api实现.读取参数化接口说明 import TestApiclass ReadFileData: def __init__(se ...
- Java 判断 循环
一.优先级 1.1 先判断5>3,true 6>4 true;然后true==true ,最后是true; 1.2 6>5,true;而true和4无法比较.所以该判断出错: 1.3 ...
- Java递归练习201908091049
package org.jimmy.autofactory.test; public class TestRecursive20190809 { public static void main(Str ...
- A AK的距离
时间限制 : - MS 空间限制 : - KB 评测说明 : 1s,128m 问题描述 同学们总想AK.于是何老板给出一个由大写字母构成的字符串,他想你帮忙找出其中距离最远的一对'A'和'K'. ...
- E1. String Coloring (easy version)(贪心)
E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes ...
- H、Magic necklace
链接:https://ac.nowcoder.com/acm/contest/3570/H 来源:牛客网 题目描述 There was a magic necklace. The necklace i ...