Dungeon Master (三维bfs)
Is an escape possible? If yes, how long will it take?
Input
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.
Output
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
Sample Input
3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0
Sample Output
Escaped in 11 minute(s).
Trapped!
//因为是三维寻找路径,又是最短路径,所以用bfs
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
char a[][][];
int b[][][];
int L,R,C;
int f[][]={{,-,, ,, },
{, ,,-,, },
{, ,, ,,-}};
int s2[][][];
int flag;
struct Knot
{
int x,y,z;
int step;
};
Knot c,d;
bool search1(int x,int y,int z)
{
return (x>=&&x<=L&&y>=&&y<=R&&z>=&&z<=C);
}
int bfs(int si,int sj,int sk)
{
queue<Knot>s;
c.x=si;
c.y=sj;
c.z=sk;
c.step=;
s.push(c);
while (!s.empty())
{
d=s.front();
s.pop();
c.step=d.step+;
for (int i=;i<;i++)
{
c.x=d.x+f[][i];
c.y=d.y+f[][i];
c.z=d.z+f[][i];
if (search1(c.x,c.y,c.z)&&!b[c.x][c.y][c.z]&&a[c.x][c.y][c.z]!='#')
{
if (a[c.x][c.y][c.z]=='E')
return c.step;
b[c.x][c.y][c.z]=;
s.push(c);
}
}
}
return -;
}
int main()
{
int i,j,k;
int si,sj,sk;
while (cin>>L>>R>>C&&(L!=||R!=||C!=))
{
memset(b,,sizeof(b));
for (i=;i<=L;i++)
for (j=;j<=R;j++)
for (k=;k<=C;k++)
{
cin>>a[i][j][k];
if (a[i][j][k]=='S')
{
si=i;
sj=j;
sk=k;
}
}
flag=bfs(si,sj,sk);
if (flag==-)
cout << "Trapped!" << endl;
else
cout << "Escaped in " << flag << " minute(s)." << endl; }
return ;
}
Dungeon Master (三维bfs)的更多相关文章
- 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 ...
- ZOJ 1940 Dungeon Master 三维BFS
Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- 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个棋子的所有可行的 ...
- Dungeon Master (简单BFS)
Problem Description You are trapped in a 3D dungeon and need to find the quickest way out! The dunge ...
- POJ 2252 Dungeon Master 三维水bfs
题目: http://poj.org/problem?id=2251 #include <stdio.h> #include <string.h> #include <q ...
随机推荐
- HTTS TTLS 433
HTTP和HTTPS协议,看一篇就够了 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/x ...
- web上传文件夹
文件夹数据库处理逻辑 publicclass DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject(); ...
- RedHat下yum配置为本地或者CentOs
由于RedHat公司将yum源作为服务给用户提供,所以不能free给大家确实挺失望的,不过还好能够在RedHat上配置本地的Yum源,或者CentOS的Yum源. 这里提供两种方式,一种是配置本地的, ...
- Module not found: Error: Can't resolve ' vue-resource'
问题: 在学习vue的过程中出现了这个问题,说明VueResource模块没有安装. 解决方法: 打开终端,进入当前项目所在目录,输入指令 npm install vue-resource --sav ...
- http三次握手,四次挥手
本文经过借鉴书籍资料.他人博客总结出的知识点,欢迎提问 序列号seq:占4个字节,用来标记数据段的顺序,TCP把连接中发送的所有数据字节都编上一个序号,第一个字节的编号由本地随机产生:给字节编上序号后 ...
- 【Django】搭建Django administration并登录
Python自带一个后台管理系统,这个后台管理系统搭建与登陆呢? 新建项目Django_Admin 文件结构目录如下: 创建APP 在pycharm下方的terminal终端中输入命令: python ...
- enum简单使用
前台传入weightCode :1/2/3/4,获取不同的区间0~10 10~50 50~100 100~999999 0~999999 public void setWeight(){ this.m ...
- Oracle JET mobile 入门使用
Oracle JET 框架能开发 window, Android, ios 的 WebApp .主要使用 Codova 来进行开发. 简单使用 Oracle JET 开发 Android webapp ...
- linux下面用Mingw编译libx264
linux下面用Mingw编译libx264 首先要先安装好mingw 我用的是Ubuntu 编译ffmpeg的时候 ,官方上面有一个自动化脚本能够把mingw安装好 这里就不说了 新版本的libx2 ...
- PHP操作SESSION
说一下在PHP里面怎么简单的操作SESSION 操作SESSION流程 <?php session_start(); //开启session $_SESSION['user']='admin'; ...