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 ...
随机推荐
- HTML5创建高德地图
创建高德地图 功能真的很好很强大,有图有证据! 1.申请key值 去官网2.https://webapi.amap.com/maps?v=1.4.11&key=e22196035aaa10db ...
- ng-项目结构
ng启动过程 目录结构 . ├── e2e 端到端测试(暂且不关心) ├── node_modules npm安装的第三方包 ├── src 存放业务源码 ├── .angular-cli.json ...
- 下载thinkphp5.0
在服务器文件中右击Git_Bash_Here打开 在命令框写入 首先克隆下载应用项目仓库 git clone https://github.com/top-think/think tp5 tp5代 ...
- 关于xshell和文件传输相关
Xshell连接linux系统 下载Xshell后启动软件 不能连接,没有弹出输入账户和密码时在linux中执行 然后再次执行Xshell 连接成功 文件传输 点击Xshell的文件传输 会引导你去安 ...
- javascript 权威指南二
1.JavaScript程序是用Unicode字符集编写的.Unicode 是ASCII和Latin-1的超级,并支持地球上几乎所有在用的语言. 2.JavaScript是区分大小写的语言.HTML并 ...
- gulp常用插件之gulp-size使用
更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-size这是一款显示项目的大小插件. 更多使用文档请点击访问gulp-size工具官网. 安装 一键安装不多解释 npm install ...
- AMC Problems and Solutions
AMC Problems and Solutions:https://artofproblemsolving.com/wiki/index.php/AMC_Problems_and_Solutions ...
- vue之项目打包部署到服务器
这是今年的第一篇博客.整理一下vue如何从项目打包到部署服务器,给大家做下分享,希望能给大家带来或多或少的帮助,喜欢的大佬们可以给个小赞,如果有问题也可以一起讨论下. 第一步:这是很关键的一步.打开项 ...
- java8的ConcurrentHashMap为何放弃分段锁,为什么要使用CAS+Synchronized取代Segment+ReentrantLock
原文地址:https://cloud.tencent.com/developer/article/1509556 推荐一篇 ConcurrentHashMap 和 HashMap 写的比较的的文章 j ...
- 微信小程序:如何判断数组中的条数?
可以<view wx:if="{{list.length == 0}}"> </view> 可以在 {{}} 内进行简单的运算,包括三元运算符.逻辑判断.算 ...