<题目链接>

题目大意:

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

解题分析:

与普通的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. restricted 模式及其 使用

    什么是数据库的RESTRICTED 模式 注:以下内容来至:百度知道 --数据库受限模式,在这个模式下只有RESTRICTED SESSION 权限的人才可以登陆,一般用与数据库维护的时候使用. RE ...

  2. 使用pm2离线部署nodejs项目

    1.下载https://npm.taobao.org/mirrors/node/v8.11.1/node-v8.11.1-linux-x64.tar.xz 比如安装到/opt目录 xz -d node ...

  3. JS实现的ajax和同源策略

    一.回顾jQuery实现的ajax 首先说一下ajax的优缺点 优点: AJAX使用Javascript技术向服务器发送异步请求: AJAX无须刷新整个页面: 因为服务器响应内容不再是整个页面,而是页 ...

  4. spring boot 自动配置原理

    1).spring boot启动的时候加载主配置类,开启了自动配置功能@EnableAutoConfiguration,先看一下启动类的main方法 public ConfigurableApplic ...

  5. 【mysql】删除字段的最后一个字符

    场景:在存入16进制id时,由于转换失误,得到的结果是0x1001L的格式,我希望转换为0x1001,去掉最后的L 指令: update tb_test set hexid=left(hexid, l ...

  6. this容易混淆的示例

    [注]this 永远不会混乱,混乱的是我们而已. /* this永远指向当前函数的主人. this混乱: 1.添加了定时器/延时器 2.事件绑定 [注]函数如果发生了赋值,this就混乱了. */ 示 ...

  7. shell脚本批量创建用户

    #!/bin/bash DATE=$(date +%F_%T) USER_FILE=user.txt echo_color() { == "green" ];then echo - ...

  8. Python内置模块之random

    random的方法有 random.random # 返回一个随机的小数 ramdom.uniform # 按照一个区间返回一个小数 random.randint # 返回一个整数 random.ra ...

  9. [转] Webpack的devtool和source maps

    source maps Webpack打包生成的.map后缀文件,使得我们的开发调试更加方便,它能帮助我们链接到断点对应的源代码的位置进行调试(//# souceURL),而devtool就是用来指定 ...

  10. (6).NET CORE微服务 Micro-Service ---- AOP框架

    AOP 框架基础 要求懂的知识:AOP.Filter.反射(Attribute). 如果直接使用 Polly,那么就会造成业务代码中混杂大量的业务无关代码.我们使用 AOP (如果不了解 AOP,请自 ...