Virtual Judge POJ 2251 Dungeon Master
三维数组加宽搜
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
const int MAXN=;
int c, k, h;
char ma[MAXN][MAXN][MAXN]; //定义三维数组 长宽高
int visit[MAXN][MAXN][MAXN]; //标记数组
struct node {
int c, k, h;//结构体记录到达某个点 c长k宽h高
int step;//走的步数
};
struct node t[];//结构体队列
struct node p, q, w, l;
int f[][] = {,,, ,,-, ,,, ,-,, ,,, -,,};//向上下左右前后六个方向移动 包括上楼
void bfs() {
visit[p.c][p.k][p.h] = ;//标记已经走过
int front = , rear = ;
t[rear++] = p;//入队
while(front!=rear) { //当队列不为空的时候
w = t[front++];
if(w.c==q.c&&w.k==q.k&&w.h==q.h) { //如果是终点,直接输出
printf("Escaped in %d minute(s).\n", w.step);
return ;
}
for(int i=; i<; i++) { //否则,遍历六个方向
l = w;
l.c += f[i][];
l.k += f[i][];
l.h += f[i][];
if(l.c>=&&l.c<c&&l.k>=&&l.k<k&&l.h>=&&l.h<h&&ma[l.c][l.k][l.h]!='#'&&visit[l.c][l.k][l.h]==) { //如果符合条件
l.step++;//步数增加
visit[l.c][l.k][l.h] = ;//标记访问过了
t[rear++] = l;//入列
}
}
}
printf("Trapped!\n");//否则,输出无法到达
}
int main() {
memset(t, , sizeof(struct node)); //先清空
while(~scanf("%d %d %d", &c, &k, &h)) { //c长k宽h高
if(c==&&k==&&h==) break;
for(int i=; i<c; i++) {
for(int j=; j<k; j++) {
scanf("%s", ma[i][j]);//按照字符串输入
for(int w = ; w<h; w++) {
if(ma[i][j][w]=='S') { //记录起点
p.c = i;
p.k = j;
p.h = w;
p.step = ;
} else if(ma[i][j][w]=='E') { //记录终点
q.c = i;
q.k = j;
q.h = w;
}
}
}
}
memset(visit, , sizeof(visit));//清空标记数组
bfs();//广搜
}
return ;
}
Virtual Judge POJ 2251 Dungeon Master的更多相关文章
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)
POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
随机推荐
- windows定时重启
先准备好脚本restart.bat 新建一个txt,写入shutdown shutdown -s -t 10 十秒后重启,更改后缀为.bat批处理文件,切记编辑好后缀千万不要直接点开,否则就会直接调用 ...
- ASP.NET Identity系列教程-3【运用ASP.NET Identity】
https://www.cnblogs.com/r01cn/p/5180892.html 14 运用ASP.NET Identity In this chapter, I show you how t ...
- Android中的内存管理机制以及正确的使用方式
概述 从操作系统的角度来说,内存就是一块数据存储区域,属于可被操作系统调度的资源.现代多任务(进程)的操作系统中,内存管理尤为重要,操作系统需要为每一个进程合理的分配内存资源,所以可以从两方面来理解操 ...
- C++中的IO类(iostream, fstream, stringstream)小结(转)
原文地址:https://blog.csdn.net/stpeace/article/details/44763009
- .NetCore3.0短网址项目
Wei.TinyUrl 基于.NetCore3.0 + Mysql开发的短网址项目 项目地址:https://github.com/a34546/Wei.TinyUrl 演示效果: 快速开始 1. 修 ...
- C# LINQ学习笔记一:走进LINQ的世界
本笔记摘抄自:https://www.cnblogs.com/liqingwen/p/5832322.html,记录一下学习过程以备后续查用. LINQ 简介: 语言集成查询(LINQ)是Vi ...
- pod has unbound immediate PersistentVolumeClaims : statefulset挂载不上pv的另一种情况
大家都直到当volumeClaimTemplates匹配不上pv时,会出现statefulset挂载不到pv的问题.错误提示如下: error while running "VolumeBi ...
- 数据预处理 | python 第三方库 imblearn 处理样本分布不均衡问题
说明:目前 只记录了 过采样 和 欠采样 的代码部分 1 样本分布不均衡描述: 主要出现在与分类相关的建模问题上,不均衡指的是不同类别的样本量差异非常大. 样本量差距过大会影响到建模结果 2 出现的场 ...
- H3C接口管理配置
一.接口批量配置 当多个接口需要配置某功能(比如shutdown)时,需要逐个进入接口视图,在每个接口执行一遍命令,比较繁琐.此时,可以使用接口批量配置功能,对接口进行批量配置,节省配置工作量. 1. ...
- Pytest学习9-常用插件
pytest-django:为django应用程序编写测试. pytest-twisted:为twisted应用程序编写测试,启动反应堆并处理测试函数的延迟. pytest-cov:覆盖率报告,与分布 ...