<题目链接>

题目大意:

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

解题分析:

与普通的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. IntelliJ IDEA使用教程 (总目录篇)

    注:本文来源于<    IntelliJ IDEA使用教程 (总目录篇)  > IntelliJ IDEA使用教程 (总目录篇) 硬件要求 IntelliJ IDEA 的硬件要求 安装包云 ...

  2. nginx官方模块之http_sub_status_module

    作用 显示nginx的连接状态,nginx客户端状态 配置语法 配置

  3. vue 中axios 的基本配置和基本概念

    axios的基本概念及安装配置方法   ajax:异步请求,是一种无需再重新加载整个网页的情况下,能够更新部分网页的技术 axios:用于浏览器和node.js的基于promise的HTTP客户端 a ...

  4. LeetCode(119):杨辉三角 II

    Easy! 题目描述: 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 3 输出: [1,3,3,1] 进阶: ...

  5. 【python】gearman阻塞非阻塞,同步/异步,状态

    参考: http://pythonhosted.org/gearman/client.html?highlight=submit_multiple_jobs#gearman.client.Gearma ...

  6. Layers Of Caffe

    本文试图描述构建一个网络结构的layers,可以用prototxt脚本直接写,也可以用python接口实现. 最简单的神经网络包含但不限于以下四部分: 数据层(Data): Data.ImageDat ...

  7. 解决linux下svn update 产生Node remains in conflict的问题

    提交一个文件 服务器上死活更新不了 是因为有冲突,解决办法:svn revert --depth=infinity /var/SvnProject/APITest 再次执行更新 进有改动的文件夹,更新 ...

  8. C++ 使用LockWorkStation()的过程遇到的问题

    关于函数“LockWorkStation()”,参见:https://msdn.microsoft.com/en-us/library/windows/desktop/aa376875.aspx Ho ...

  9. jQuery之导航菜单(点击该父节点时子节点显示,同时子节点的同级隐藏,但是同级的父节点始终显示)

    注:对于同一个对象不超过3个操作的,可直接写成一行,超 过3个操作的建议每行写一个操作.这样可读性较强,可提高代码的可读性和可维护性 核心代码: $(".has_children" ...

  10. 详解C程序编译、链接与存储空间布局

    被隐藏了的过程 现如今在流行的集成开发环境下我们很少需要关注编译和链接的过程,而隐藏在程序运行期间的细节过程可不简单,即使使用命令行来编译一个源代码文件,简单的一句"gcc hello.c& ...