BFS POJ2251 Dungeon Master
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
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水题,套模板按6个方向拓展就行了。
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string.h>
using namespace std;
int to[][] = {{,,},{,,-},{,,},{,-,},{,,},{-,,}};
char s[][][];
int maps[][][];
int x1,y1,z1;
int x2,y2,z2;
int L,R,C;
struct data
{
int x;
int y;
int z;
int step;
};
int check(int x,int y,int z)
{
if(x< || y< || z< || x>=L || y>=R || z>=C)
return ;
else if(s[x][y][z] == '#')
return ;
else if(maps[x][y][z])
return ;
return ;
}
int bfs()
{
queue<data> q;
data now,nex;
now.x=x1;
now.y=y1;
now.z=z1;
now.step=;
maps[x1][y1][z1]=;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
if(now.x==x2&&now.y==y2&&now.z==z2)
{
return now.step;
}
for(int i=;i<;i++)
{ nex=now;
nex.x=now.x+to[i][];
nex.y=now.y+to[i][];
nex.z=now.z+to[i][];
if(check(nex.x,nex.y,nex.z))
{
continue;
}
maps[nex.x][nex.y][nex.z]=;
nex.step=now.step+;
q.push(nex);
}
}
return ;
}
int main()
{
while(scanf("%d%d%d",&L,&R,&C),L+R+C)
{
cin>>R>>C;
int i,j,k;
for(i=;i<L;i++) //
{
for(j=;j<R;j++)
{
scanf("%s",s[i][j]);
for(k=;k<C;k++)
{
if(s[i][j][k]=='S')
{
x1=i;
y1=j;
z1=k;
}
else if(s[i][j][k]=='E')
{
x2=i;
y2=j;
z2=k;
}
}
}
}
memset(maps,,sizeof(maps));
int ans;
ans=bfs();
if(ans)
{printf("Escaped in %d minute(s).\n",ans);}
else
{
printf("Trapped!\n");
}
}
return ;
}
BFS POJ2251 Dungeon Master的更多相关文章
- POJ2251 Dungeon Master —— BFS
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- POJ2251 Dungeon Master(bfs)
题目链接. 题目大意: 三维迷宫,搜索从s到e的最小步骤数. 分析: #include <iostream> #include <cstdio> #include <cs ...
- POJ2251——Dungeon Master(三维BFS)
和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...
- bfs—Dungeon Master—poj2251
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32228 Accepted: 12378 ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
随机推荐
- android adb shell input各种妙用
项目中使用一个开发版,预留两个usb接口.类似华硕TinkerBoard. 一个用户连接摄像头,一个用于adb调试.结果就没了鼠标的接口.多次切换鼠标和摄像头插头,非常不方便,带摄像头的app没法调试 ...
- BZOJ 4503: 两个串 [FFT]
4503: 两个串 题意:兔子们在玩两个串的游戏.给定两个只含小写字母的字符串S和T,兔子们想知道T在S中出现了几次, 分别在哪些位置出现.注意T中可能有"?"字符,这个字符可以匹 ...
- (python基础)时间辍time、时间元组localtime、时间格式化strftime
可以直接将下方代码运行查看结果:#!/usr/bin/python# coding=utf-8import time # 引入time模块# 时间戳:# 每个时间戳都以自从1970年1月1日午夜(历元 ...
- S5PV210中断处理
_start: 1.设置栈空间:防止之前的UBOOT代码被覆盖,应为c中需要栈空间 ldr sp, =0x40010000 2.设置CPSR的I,F位,A8打开IRQ,FIQ中断: mov r0, # ...
- 【翻译】CSS Animations VS the Web Animations API:案例学习
原文地址:CSS Animations vs the Web Animations API: A Case Study May 03, 2017 css, javascript 上周我写了我如何使用C ...
- python通过一个语句分析几个常用函数和概念
前言 过年也没完全闲着,每天用一点点时间学点东西,本文为大家介绍几个python操作的细节,包含all.any.for in等操作,以及介绍我解决问题的思路. 一.开篇 先从我看到的一个简单的语句开始 ...
- 【转】APACHE RewriteEngine用途
首先要学会怎么设置 httpd.conf 的设置, 什么 ALL 就不用用说了 要看你的 httpd.conf 是否设置正确了,很简单,只要你在 .htaccess 里随便录入一些 比如 adbas ...
- CentOS下安装XAMPP详细教程(转)
[原文]http://blog.csdn.net/hel12he/article/details/49781813 现在PHP的集成运行环境越来越多,个人比较喜欢XAMPP,更新速度快,好用,安装便捷 ...
- 说说VNode节点(Vue.js实现)
写在前面 因为对Vue.js很感兴趣,而且平时工作的技术栈也是Vue.js,这几个月花了些时间研究学习了一下Vue.js源码,并做了总结与输出.文章的原地址:https://github.com/an ...
- Java中从键盘输入的三种方法
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...