ZOJ 1940 Dungeon Master【三维BFS】
<题目链接>
题目大意:
在一个立体迷宫中,问你从起点走到终点的最少步数。
解题分析:
与普通的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】的更多相关文章
- ZOJ 1940 Dungeon Master 三维BFS
Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- 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 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- Dungeon Master(三维bfs)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- UVa532 Dungeon Master 三维迷宫
学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #i ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- 棋盘问题(DFS)& Dungeon Master (BFS)
1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...
随机推荐
- Android源码分析二 硬件抽象层(HAL)
一 什么是HAL HAL 可定义一个标准接口以供硬件供应商实现,这可让 Android 忽略较低级别的驱动程序实现.借助 HAL,您可以顺利实现相关功能,而不会影响或更改更高级别的系统.HAL 实现会 ...
- PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /usr/local/php/CreateDB.php on line 5
原因:php还不支持mysql8.0最新的密码加密方式 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ' ...
- laravel 5 优化
性能一直是 Laravel 框架为人诟病的一个点,所以调优 Laravel 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论. 这里是简单的列表: 配 ...
- Client-Side Attacks
1.之前看到中间人攻击方式,要使用ssl服务构架一个劫持会话,使得攻击者和被攻击者客户端连接.ssl 服务(secure Socket Layer安全套接) ,以及后续出现的TSL(Transport ...
- hdu2196 树形dp经典|树的直径
/* 两种做法 1.求出树直径v1,v2,那么有一个性质:任取一点u,树上到u距离最远的点必定是v1或v2 那么可以一次dfs求树v1 第二次求dis1[],求出所有点到v1的距离,同时求出v2 第三 ...
- appium如何解决每次都要安装apk的烦恼
1.appium上勾选 No Reset 2.程序加上:capabilities.setCapability("noReset", true); //不需要再次安装 3.命令行 ...
- 安装cx_Oracle 6
首先声明,本文是在Linux 环境下进行安装.不涉及Windows 版安装. 一. 了解cx_Oracle 安装要求 要python 通过cx_Oracle 6 操作Oracle 数据库,以下几个条件 ...
- document.getElementsByClassName() 原生方法 通过className 选择DOM节点
<div id="box"> <div class="box">1</div> <div class="bo ...
- MyEclipes相关配置
0. MyEclipes10 相关下载资源(私人珍藏版) 链接:http://pan.baidu.com/s/1eSIdObS密码:0cjy 1. myEclipes连接Tomcat http://w ...
- 爬虫(猫眼电影+校花网+github+今日头条+拉钩)
Requests+正则表达式爬取猫眼TOP100榜电影信息 MARK:将信息写入文件解决乱码方法,开启进程池秒爬. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...