三维数组加宽搜

#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的更多相关文章

  1. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  2. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  3. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  4. 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 ...

  5. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  6. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  7. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  8. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  9. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

随机推荐

  1. Jenkins-Publish Over SSH插件

    插件安装 打开Jenkins的“系统管理>管理插件”,选择“可选插件”,在输入框中输入“Publish over SSH”进行搜索,如果搜索不到可以在“已安装”里确认是否已经安装过.在搜索结果中 ...

  2. Building a Space Station POJ - 2031 三维最小生成树,其实就是板子题

    #include<iostream> #include<cmath> #include<algorithm> #include<cstdio> usin ...

  3. Codeforces Round #615 (Div. 3) 补题记录

    第一次搞CF,结果惨不忍睹...还是太菜了 A:要用到全部的钱,所以总数必须是3的倍数,而且初始状态下任意一人的钱数不能超过总数除以3,否则没法分了 (也就这个签到算是在我能力范围之内了....) # ...

  4. 问题 C: 神奇的口袋

    #include <cstdio> using namespace std; int n1; int nums[99]; int help(int i, int sum) { if (su ...

  5. C# 引入Sqlite 未能加载文件或程序集“System.Data.SQLite

    个人博客 地址:https://www.wenhaofan.com/article/20190501224046 问题 在Visual Studio 中 使用NuGet 通过 install-pack ...

  6. poj1000-1009小结

    poj1000-1009小结 poj1000-1009小结 poj1000 AB poj1001 Exponentiation poj1002 poj1003 poj1004 Financial Ma ...

  7. 843. n-皇后问题(dfs+输出各种情况)

    n-皇后问题是指将 n 个皇后放在 n∗n 的国际象棋棋盘上,使得皇后不能相互攻击到,即任意两个皇后都不能处于同一行.同一列或同一斜线上. 现在给定整数n,请你输出所有的满足条件的棋子摆法. 输入格式 ...

  8. JS编解码与Java编解码的对应关系

    最近前段在导出数据时会遇到“illegal character”的异常错误,结果发现是在请求地址中请求参数包含了空白字符(其编码为%C2%A0)或者是空格字符(其编码为%20),之前对空格字符情况是做 ...

  9. ASP.NET Razor 常用示例

    1.在网页中显示@符号 使用@@即可使编译器不切换到c#,这样在网页中会显示一个@符号. 2.隐式表达式 也就是正常的razor语法,不能包含空格.(除了await 如:<p>@await ...

  10. Java中8进制数和16进制数的表示方法

    由于数据在计算机中的表示,最终以二进制的形式存在,所以有时候使用二进制,可以更直观地解决问题.  但,二进制数太长了.比如int   类型占用4个字节,32位.比如100,用int类型的二进制数表达将 ...