Dungeon Master POJ - 2251(三维BFS+Queue+模板题)

量子通信:初识量子城域网 对量子城域网的概念、作用、拓扑、建设内容等进行了较为全面的初步介绍。 阅读详情

You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.

Is an escape possible? If yes, how long will it take?
Input
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
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
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
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!

题意:

S为起点,E为终点,计算从S走到E需要的时间?#为岩石不可走,. 可走

思路:

三维BFS 模板题

可以将这个图看作是一个有L层的楼,有六个方向,即上下左右前后,然后进行搜索即可。

代码:

#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;
int dir[6][3]={0,0,1,0,0,-1,-1,0,0,1,0,0,0,1,0,0,-1,0};
int book[42][42][42];
char mp[42][42][42];
int l,r,c;
int sx,sy,sz,ex,ey,ez;
struct node
{
    int x,y,z,s;
}u,v;

int bfs()
{
    queue<node>q;
    u.x=sx;
    u.y=sy;
    u.z=sz;
    u.s=0;
    book[sx][sy][sz]=1;
    q.push(u);
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        if(u.x==ex&&u.y==ey&&u.z==ez)
           return u.s;
        for(int i=0;i<6;i++)
        {
            v.x=u.x+dir[i][0];
            v.y=u.y+dir[i][1];
            v.z=u.z+dir[i][2];
            if(v.x>=0&&v.x<l&&v.y>=0&&v.y<r&&v.z>=0&&v.z<c&&mp[v.x][v.y][v.z]!='#'&&!book[v.x][v.y][v.z])
            {
                book[v.x][v.y][v.z]=1;
                v.s=u.s+1;
                q.push(v);

            }
        }
    }
    return 0;
}
int main()
{

    while(~scanf("%d %d %d",&l,&r,&c)&&l+r+c)
    {
        memset(book,0,sizeof(book));
        for(int i=0;i<l;i++)
        {
            for(int j=0;j<r;j++)
            {
                scanf("%s",mp[i][j]);
                for(int k=0;k<c;k++)
                {
                    if(mp[i][j][k]=='S')
                    {
                        sx=i;
                        sy=j;
                        sz=k;
                    }
                    else if(mp[i][j][k]=='E')
                    {
                        ex=i;
                        ey=j;
                        ez=k;
                    }
                }
            }
        }
        int ans;
        ans=bfs();
        if(ans)
            printf("Escaped in %d minute(s).\n",ans);
        else
            printf("Trapped!\n");
    }
    return 0;
}
【软件测试】- 公有云、私有云、混合云简介以及如何在公有云与私有云上分别搭建测试环境 公有云、私有云以及混合云是目前云计算领域的三种主要模式。它们之间的区别主要在于部署方式、数据访问和管理控制的不同。在阿里云或腾讯云上使用 Kubernetes 和 Docker 搭建测试环境可以提供高度的可伸缩性和灵活性。这样的环境非常适合于需要在多种配置和条件下进行测试的复杂应用。通过云服务提供的工具和服务,可以轻松管理和监控整个测试过程。在云服务上搭建测试环境涉及选择合适的云提供商、配置云资源、安装和设置所需软件等步骤。### 1. 选择云服务提供商。 阅读详情

相关推荐

DFT与机器学习协同设计高效光催化剂:从电子结构到性能预测

密度泛函理论(DFT)作为计算材料学的基石,通过求解Kohn-Sham方程,能够在原子尺度精确预测材料的电子结构、能带和光学性质,为理解光催化等能源材料的微观机理提供了关键视角。其核心价值在于替代传统试错法,实现材料性能的理性设计与机理揭示。在工程实践中,面对高通量筛选的需求,机器学习(ML)技术,特别是长短期记忆网络(LSTM)这类擅长处理序列数据的模型,能够学习从材料描述符到复杂性能(如光谱)的映射关系,实现快速性能预测与优化。这种DFT与ML的结合范式,正广泛应用于新能源材料、半导体器件等领域,用于高

weixin_30662937的博客 662

POJ2251:Dungeon Master(BFS)

Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit

ACM!荣耀之路! 1万+

FPGA DMA IP核使用指南

数据传输:支持从源地址到目标地址的数据传输。中断管理:提供中断信号,便于CPU处理传输完成事件。传输控制:支持传输大小、方向和暂停/恢复控制。

weixin_66634995的博客 2428

POJ-2251 Dungeon Master

POJ-2251 Dungeon Master You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You ca

sdudyl的博客 277

告别unittest!用Pytest+Fixture重构你的Python测试代码(附实战案例)

本文详细介绍了如何从unittest迁移到Pytest框架,重点解析了Pytest的Fixture机制如何提升测试效率和代码简洁性。通过实战案例展示了Pytest在减少代码量、提升调试效率和资源管理方面的优势,帮助开发者重构Python测试代码。

weixin_26749245的博客 206

单反相机物镜设计[DG-10]

REAR(要打在像面,操作数要找像面对应位置15):以透镜单位表示的真实光线径向坐标,波长由Wave定义,参见“Hx、Hy、Px和Py”。最小玻璃厚度最小不能小于semi-dia的1/10,要根据layout看有没有过厚过薄,反复调节。PROD:两个操作数的乘积(操作#1 X操作#2)。3x4就是57.3x0.41=23.5。拦光一般在第一面和最后一面操作,减少边缘无用光线。光阑面与镜面贴近,要调距离,同时设置光阑像差。后截距是指从镜头后表面到焦点的距离。CONS:弧度转为角度。镜头相互嵌入,有错误。

weixin_72050316的博客 600

Dungeon Master(题解)

题目 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, so...

CHAI_NIAOJINJE的博客 1427

ROS机器人未知环境自主探索功能包explore_lite总结

本系列文章主要针对ROS机器人常使用的未知环境自主探索功能包explore_lite展开全源码的详细解析,并进行概括总结。 本系列文章共包含六篇文章,前五篇文章主要介绍explore_lite功能包中 explore.cpp、costmap_tools.h、frontier_search.cpp、costmap_client.cpp等源码实现文件中全部函数的详细介绍,第六篇文章进行概括总结,包含自主探索功能包explore_lite的简介,实现未知环境自主探索功能的原理及流程总结,效果演示,使用功能包exp

慕羽★的博客 4461

NOI题库 1253:Dungeon Master

描述 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, so

LOI__DiJiang的博客 866

ResNet改进(50):SKConv和CBAM增强的ResNet模型

动态调整感受野大小- 结合通道和空间注意力模型的核心思想是在ResNet的每个残差块后插入这些注意力模块,使网络能够自适应地关注更重要的特征。模型的核心是类,它在标准ResNet34的基础上:替换了初始卷积层,使用更小的核(3×3)和步长(1)在每个残差块后选择性添加SKConv和CBAM模块# 加载预训练ResNet34# 自定义初始层# 添加注意力机制的残差层通过集成SKConv和CBAM,这个改进的ResNet模型能够更有效地捕捉多尺度特征并关注关键信息区域。

2401_82355416的博客 621

AI时代的软件质量保证新方法论

3.2.1 质量保证的方法论 质量保证(Quality Assurance, QA)是一种系统化的方法,用于确保产品或服务符合预定的质量标准。在AI时代,软件质量保证的方法论需要适应不断变化的AI技术和应用场景。 3.2.1.1 质量管理体系的构建 首先,构建一个完善

AI天才研究院 1353

英语题目翻译——OJ_ 1253:Dungeon Master

题目:1253:Dungeon Master(OpenJudge - 1253:Dungeon Master) 翻译: 你被困在一个3D地牢里,需要找到最快的出路!地牢是由单元立方体组成的,这些立方体可以填充也可以不填充岩石。向东、西、北、南、上、下移动一个单位需要一分钟。你不能沿对角线移动,而且迷宫四周都是坚固的岩石。 逃脱是可能的么吗?如果可以,需要多长时间? 输入 输入许多地牢。每个地牢的描述开始于一行包含三个整数L, R和C(大小限制在30)。 L表示组成地下城的关卡数量。R和C是组成每一

m0_64882565的博客 553

情感分析在金融领域的应用:舆情影响股价预测

我们都知道,股价的波动受到多种因素的影响,而大众的情绪和看法就是其中很重要的一部分。我们在日常生活中都有根据别人的评价来判断事物好坏的经验,在金融市场里,舆情就像是大众对某家公司的集体评价,它能反映出市场参与者的情绪和预期。学习这方面的知识,能帮助投资者更好地把握市场动态,做出更明智的投资决策,无论是个人投资者还是金融机构的分析师,都能从中受益。有一天,你看到某家知名企业被曝光了严重的产品质量问题,新闻铺天盖地,股民们也都在热议纷纷,负面情绪弥漫。这时,你会不会觉得这家公司的股价可能要下跌了呢?

AI 原生应用开发的博客 1147

Dungeon Master( POJ - 2251 )

Dungeon Master( POJ - 2251 )You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. Yo

BoBoo文睡不醒 1334

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

POJ-2251 Dungeon Master (BFS+优先队列)

这题是今年4月我们校队选拔时的最后一题,当时用的是一样的方法怎么做却都是WA,最后也没做出来;时隔3个月再做一遍才AC,也算填上了一个坑。。。orz Description 你被困在一个三维的空间中,现在要寻找最短路径逃生! 空间由立方体单位构成 你每次向上下前后左右移动一个单位需要一分钟 你不能对角线移动并且四周封闭 是否存在逃出生天的可能性?如果存在,则需要多少时间? Input 输入第一行...

Irimsky 251

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

POJ-2251-Dungeon Master (BFS)

POJ-2251-Dungeon Master #include #include <stdio.h> #include #include <string.h> #include using namespace std; const int max_m = 0x3f3f3f; struct node{ int x; int y; int z; }; int L, R,...

fugewo的博客 187

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

POJ2251—— BFS——Dungeon Master

http://poj.org/problem?id=2251 /* 简单bfs,向六个方向拓展 */ /************************************************ * Author :Powatr * Created Time :2015-8-9 9:23:15 * File Name :B.cpp ...

dgjm4087的博客 154

POJ 2251 Dungeon Master、BFS、三维:【题解】

Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be...

EP的别三日 284

POJ 2251 Dungeon Master (三维BFS)

题目链接 题意:XHK被困在一个三维的网吧中,现在要寻找最短路径逃生! 空间由立方体单位构成 你每次向上下前后左右移动一个单位需要一分钟 你不能对角线移动并且四周封闭 是否存在逃出生天的可能性?如果存在,则需要多少时间? 分析:二维BFS模版改成三维即可,注意bfs时临时变量不要重复使用,会套娃出错,找了半天才找到 #include <iostream> #include <cm...

爱吃猫的鱼~ 201

POJ2251 Dungeon Master BFS

Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one

colorfulshark 1081

POJ - 2251 Dungeon Master 【BFS】

题目链接 http://poj.org/problem?id=2251 题意 给出一个三维地图 给出一个起点 和 一个终点 ‘#’ 表示 墙 走不通 ‘.’ 表示 路 可以走通 求 从起点到终点的 最短路径 走不通输出 Trapped! 方向 是可以 上,下,东南西北 六个方向 思路 BFS板子题 注意要记录 S 和 E 的...

dianxi0949的博客 107

POJ-2251 Dungeon Master(BFS+queue)

题目通道 题解分析 绝对不能用dfs,否则会超时,逐层深入,一旦找到立刻退出,能使用时期望最小。 必备vis入队判重。queue存储队列。 判断continue: 1、已经入队。2、下个方块为rock。3、越界。 判断队列退出:1、队列为空(无解)。2、到达E点(得出解)。 AC代码 #include <iostream> #include <stdio.h> #inclu...

魔君的博客 155

poj2251 Dungeon Master

package bfs;import java.util.LinkedList;import java.util.Queue;import java.util.Scanner;/**问题请参考http://poj.org/problem?id=2251 * 题意:给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径移动方向可以是上,下,左,右,前,后,六个方向 * 每移动一次就耗费一分

萝卜@兔子的专栏 290

POJ2251 Dungeon Master(3D迷宫 bfs)

题目链接:http://poj.org/problem?id=2251 Dungeon Master   Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not b

hkh746392783的专栏 517

POJ 2251 Dungeon Master (BFS)

题目链接:POJ 2251 Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minu...

G19850917的博客 142

[kuangbin带你飞]专题一 简单搜索 B - Dungeon Master poj2251

poj 2251 B - Dungeon Master 简单bfs,不是第一次做了,犯了俩错误 chukou开始不小心写成了bool类 然后queue一定要在每次清空(写在bfs函数里面就行) 不然上一次没扔出来的下次被优先访问出问题。 #include&lt;stdio.h&gt; #include&lt;iostream&gt; #include&lt;string.h&gt; #includ...

小萌林的博客 260
上一篇: 计算机网络原理期末复习
下一篇: Frogger POJ - 2253(最短路+Floyd+计算两点间距离)
Piink
博客等级 码龄7年 119粉丝 195原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值