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 ...
随机推荐
- js微信禁用右上角的分享按钮,和vue中微信页面禁用右上角的分享按钮的问题
1.隐藏微信网页右上角的按钮 document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() { // 通过下面这个 ...
- [51nod 1181] 质数中的质数 - 筛法
如果一个质数,在质数列表中的编号也是质数,那么就称之为质数中的质数.例如:3 5分别是排第2和第3的质数,所以他们是质数中的质数.现在给出一个数N,求>=N的最小的质数中的质数是多少(可以考虑用 ...
- 项目部署 ubuntu Django uwsgi配置
1.进入项目文件夹 mkdir uwsgi_file vim uwsgi.ini 写入保存 [uwsgi] chdir = /home/mysite/my_project # 项目目录 module ...
- Mac 多版本 JDK 管理
Mac 多版本 JDK 管理 1. 准备 ZSH Homebrew Oracle JDK 1.8 安装包(Homebrew 官方源和第三方源不再提供老版本的 Oracle JDK) 2. 安装 JDK ...
- 0005 uwsgi配置
在配置文件目录Configurations下创建一个名为uwsgi.ini的文件,用于uwsgi服务配置. uwsgi在服务器上使用,接收nginx的转发请求. 内容如下: # 配置文件:这一行必须有 ...
- mybatis第二天01
MyBatis第二天01 1.高级结果映射 1.1根据视频案例,分析表之间的关系 数据模型分析 1. 明确每张表存储的信息 2. 明确每张表中关键字段(主键.外键.非空) 3. 明确数据库中表与表之间 ...
- Python TCP与UDP的区别
TCP:英文全拼(Transmission Control Protocol)简称传输控制协议,它是一种面向连接的.可靠的.基于字节流的传输层通信协议. TCP通信需要经过创建连接.数据传送.终止连接 ...
- -bash: mysqld: command not found
网址:https://blog.csdn.net/zq199692288/article/details/78863737
- 2个月,我从编程小白成为了Python研发工程师
从编程小白,到Python研发工程师,需要多久呢? 答案就是:91门课,450个小时. 听起来似乎难以实现,但其实如果每天抽出八小时学习,两个月的时间,就能由编程小白转变成为Python工程师,听起来 ...
- HTML-表格-基础表格
主要内容: HTML表格 基本语法和结构: 案例: border用在table标签里面,表示边框的. th标签是加粗,width是宽度,表格宽度用在table里面.: caption用在table ...