<题目链接>

题目大意:

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

解题分析:

与普通的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. Net 4.5 WebSocket 在 Windows 7, Windows 8 and Server 2012上的比较

    .Net 4.5 WebSocket Server Running on Windows 7? Net 4.5 WebSocket Server 可以运行在 Windows 7,但是Net 4.5的 ...

  2. 【sqli-labs】Less18~Less22

    Less18: User-Agent注入,有错误回显 感叹一句,越来越难了.现在只能先看代码再分析怎么注入了..... 通过代码,发现username和password均做了校验.但是会有一个插入us ...

  3. Layer-level的快速算法

    十岁的小男孩 本文为终端移植的一个小章节. Sparse Block Net 本节为优化加速的第二章节,主要介绍Sparse-block net.上章节为OP算子层的加速,本节为层级间的加速,主要针对 ...

  4. cf自训6

    cf946D 背包+区间dp 好题 /* 先预处理出每行消去i个1后可以的到的最小时间: 先求每行的前缀和,枚举左端点和右端点,消去的1 cost=tot-sum[r]+sum[l-1],区间长度=r ...

  5. Nginx详解八:Nginx基础篇之Nginx请求限制的配置语法与原理

    Nginx的请求限制: 连接频率的限制:limit_conn_module 配置语法:limit_conn_zone key zone=name:size;默认状态:-配置方法:http 配置语法:l ...

  6. windows 下命令行启动停止mysql

    MySQL比较好玩一点就是它可以用多种方式启动,当然它也可以用多种方式关闭.下面我就mysql的几种启动方式简单的谈一谈,希望可以给大家提供一些参考. 第一种,用mysqld-nt来启动. 在没有进行 ...

  7. 数据结构C++实现代码-顺序表

    参考:https://blog.csdn.net/ebowtang/article/details/43094041 //seqList.h// //包含顺序表中的声明// #include<i ...

  8. 调试WebApi的一些方法

    1.Get方法时,直接用浏览器访问 2.Postman 3.用HttpClient调用 privatevoid GetData() { using (HttpClient client = new H ...

  9. Django Web开发基础环境配置流程

    创建虚拟环境 mkvirtualenv django_py3_1.11 -p python3 注意需要联网 安装Django 使用django 1.11.11版本,注意需要联网 pip install ...

  10. Sublime Text 3 快捷键总结(拿走)

    以下是个人总结不完全的快捷键总汇,祝愿各位顺利解放自己的鼠标. 选择类 Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同 ...