(广搜)Dungeon Master -- poj -- 2251
链接:
http://poj.org/problem?id=2251
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 21370 | Accepted: 8299 |
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!
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue> using namespace std; #define N 35 struct node
{
int x, y, z, step;
}; char Map[N][N][N];
node e;
int L, R, C;
int dir[][]={{,,-},{,,},{,-,},{,,},{-,,},{,,}}; bool Judge(node s)
{
return s.x>= && s.x<L && s.y>= && s.y<R && s.z>= && s.z<C && Map[s.x][s.y][s.z]!='#';
} int BFS(node s)
{
node p;
queue<node>Q;
Q.push(s); while(Q.size())
{
s = Q.front(), Q.pop(); if(s.x==e.x && s.y==e.y && s.z==e.z) return s.step; for(int i=; i<; i++)
{
p.x = s.x + dir[i][];
p.y = s.y + dir[i][];
p.z = s.z + dir[i][];
p.step = s.step + ; if(Judge(p))
{
Q.push(p);
Map[p.x][p.y][p.z] = '#';
}
}
}
return -;
} int main()
{
while(scanf("%d%d%d", &L, &R, &C), L+R+C)
{
node s; memset(Map, , sizeof(Map)); for(int i=; i<L; i++)
for(int j=; j<R; j++)
{
scanf("%s", Map[i][j]);
for(int k=; k<C; k++)
{
if(Map[i][j][k]=='S')
s.x=i, s.y=j, s.z=k, s.step=;
if(Map[i][j][k]=='E')
e.x=i, e.y = j, e.z=k;
}
} int ans = BFS(s); if(ans==-)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n", ans);
} return ;
}
(广搜)Dungeon Master -- poj -- 2251的更多相关文章
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- Dungeon Master POJ - 2251 (搜索)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48605 Accepted: 18339 ...
- Dungeon Master POJ - 2251(bfs)
对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...
- Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- B - Dungeon Master POJ - 2251
//纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...
- kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251
题目链接:https://vjudge.net/problem/POJ-2251 题意:简单的三维地图 思路:直接上代码... #include <iostream> #include & ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- 广搜+输出路径 POJ 3414 Pots
POJ 3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13547 Accepted: 5718 ...
- POJ 2251 Dungeon Master(广搜,三维,简单)
题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...
随机推荐
- 负载均衡-haproxy安装配置
HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持 ...
- native关键字(本地方法)、 java调用so动态链接库
Java native关键字 一. 什么是Native Method 简单地讲,一个Native Method就是一个java调用非java代码的接口.一个Native Method是这样一个ja ...
- POJ 2395 Out of Hay(求最小生成树的最长边+kruskal)
Out of Hay Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18472 Accepted: 7318 Descr ...
- 机器视觉和Tesseract
机器视觉 从 Google 的无人驾驶汽车到可以识别假钞的自动售卖机,机器视觉一直都是一个应用广 泛且具有深远的影响和雄伟的愿景的领域. 我们将重点介绍机器视觉的一个分支:文字识别,介绍如何用一些 P ...
- lnmp架构实现动态php
目录 LNMP动态网站php 1.PHP-FastCGI概述 PHP-FPM安装配置 配置PHP与数据库连接 配置PHP新增扩展模块 配置PHP-FPM主要配置 配置PHP-FPM错误日志 1.编译安 ...
- IOS AudioServicesPlaySystemSound 后台锁屏播放
AudioServicesPlaySystemSound 想在锁屏后台播放报警提示音. 添加了UIBackgroundModes,audio,官方审核不通过! IOS的闹钟是怎么实现的,锁屏不能播放声 ...
- javax.persistence.RollbackException: Error while committing the transaction
the valid jpa update entity code gives the exception below in the case of wrong dependency( org.hib ...
- securecrt中使用上传下载sftp
securecrt中使用上传下载sftp SecureCRT这个工具自带了一个FTP,方便我们上传和下载,而且做的比较人性化,由于其基本命令和linux中基本命令大都相似,熟悉LINUX人能很容易 ...
- 行为型-命令模式(Command)
装修新房的最后几道工序之一是安装插座和开关,通过开关可以控制一些电器的打开和关闭,例如电灯或者排气扇.在购买开关时,我们并不知道它将来到底用于控制什么电器,也就是说,开关与电灯.排气扇并无直接关系,一 ...
- 【转】楼天城楼教主的acm心路历程(作为励志用)
利用假期空闲之时,将这几年GCJ,ACM,TopCoder 参加的一些重要比赛作个回顾.昨天是GCJ2006 的回忆,今天时间上更早一些吧,我现在还清晰记得3 年前,我刚刚参加ACM 时参加北京赛区2 ...