<题目链接>

题目大意:

在一个立体迷宫中,问你从起点走到终点的最少步数。

解题分析:

与普通的BFS基本类似,只需要给数组多加一维,并且走的时候多加 上、下这两个方向就行。

#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std; int a,b,c;
char mpa[][][];
int vis[][][];
int dir[][]={{,,},{-,,},{,,},{,,},{,-,},{,,-}}; struct node{
int x,y,z;
int step;
node(int a=,int b=,int c=,int d=){
x=a,y=b,z=c,step=d;
}
}st,et; void bfs(){
memset(vis,,sizeof(vis));
queue<node>q;
q.push(st);
vis[st.x][st.y][st.z]=;
while(!q.empty()){
node now=q.front();
q.pop();
if(now.x==et.x&&now.y==et.y&&now.z==et.z){
printf("Escaped in %d minute(s).\n",now.step);
return;
}
for(int i=;i<;i++){
int xx=now.x+dir[i][];
int yy=now.y+dir[i][];
int zz=now.z+dir[i][];
if(xx<||xx>a||yy<||yy>b||zz<||zz>c||vis[xx][yy][zz]||mpa[xx][yy][zz]=='#')continue;
vis[xx][yy][zz]=;
q.push(node(xx,yy,zz,now.step+));
}
}
printf("Trapped!\n");
} int main(){
while(scanf("%d %d %d",&a,&b,&c)!=EOF,a||b||c){ for(int i=;i<=a;i++){
getchar();
for(int j=;j<=b;j++){
scanf("%s",mpa[i][j]+);
for(int k=;k<=c;k++){
if(mpa[i][j][k]=='S')st=node(i,j,k,);
if(mpa[i][j][k]=='E')et=node(i,j,k,);
}
}
} bfs(); }
return ;
}

2018-08-30

ZOJ 1940 Dungeon Master【三维BFS】的更多相关文章

  1. ZOJ 1940 Dungeon Master 三维BFS

    Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Desc ...

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

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

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

  4. POJ 2251 Dungeon Master (三维BFS)

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

  5. POJ:Dungeon Master(三维bfs模板题)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16748   Accepted: 6522 D ...

  6. Dungeon Master(三维bfs)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  7. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

  8. 【POJ - 2251】Dungeon Master (bfs+优先队列)

    Dungeon Master  Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...

  9. 棋盘问题(DFS)& Dungeon Master (BFS)

    1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...

随机推荐

  1. Oracle 所有的权限列表

  2. ( linker command failed with exit code 1) 错误解决方案 项目使用的是pod

    targets -> build settings -> architectures -> build active architecture only -> debug 改成 ...

  3. JAVA项目中常用的异常处理情况总结

    JAVA项目中常用的异常知识点总结 1. java.lang.nullpointerexception这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用 ...

  4. xilinx_all_version.lic

    INCREMENT ISE_Vivado_Seth xilinxd -dec- uncounted \ C25FB036D304 VENDOR_STRING=License_Type:Bought H ...

  5. 理解call及apply

    转载自:http://www.zhihu.com/question/20289071 //call 和 apply 都是为了改变某个函数运行时的 context 即上下文而存在的,换句话说,就是为了改 ...

  6. Workbench热水泵系统

    1.创建一个新的项目,首先新建一个station,打开platform(链接配置,端口设置,账户设置) 新建文件夹之后模板的选取从palette中选择. 第一步新建station,键入station名 ...

  7. Mesh无线网络的定义与WiFi的区别

    Mesh无线网络的定义与WiFi的区别 无线Mesh网络(无线网状网络)也称为「多跳(multi-hop)」网络,它是一种与传统无线网络完全不同的新型无线网络技术.无线网状网是一种基于多跳路由,对等网 ...

  8. Nginx详解二十四:Nginx深度学习篇之灰度发布

    实战场景 - 灰度发布 灰度发布的作用:按照一定的关系区别,分部分的代码进行上线,使代码的发布能平滑过渡上线实现方式: 1.用户的信息cookie等信息区别 2.根据用户的IP地址 安装memcach ...

  9. go的gin框架从请求中获取参数的方法

    前言: go语言的gin框架go里面比较好的一个web框架, github的start数超过了18000.可见此框架的可信度 如何获取请求中的参数 假如有这么一个请求: POST   /post/te ...

  10. 制作linux下的.run安装包

    前言 之前往linux上安装一个软件,都是以压缩包或者压缩包+shell的方法,这每次安装,都是先scp到某个目录, 解压,安装......稍微厉害的,会写个shell脚本.但是还是达不到真正的快速方 ...