hdu1072 Nightmare

广搜(bfs)模板太好用了!bfs详细讲解--超详细题目分析(持续更新题目----)【算法分享】 广搜讲解目录广搜回顾广搜题目noj1541八数码问题题目描述:题目要求即样例题目分析题解代码【注解详细】---理解BFSnoj1652 僵尸来了题目描述题目要求及样例题目分析题目代码(注解详细) 广搜回顾 上一篇博客我已经和大家从整体上分析了广搜bfs,深搜dfs和递归,对于广搜,举了一道例题,就是noj的加一乘二平方,当时借助这个题目就和大家分享了bfs求解的一般模式----取出根节点u,扩展u,当然使用的是while循环 这个题目非常简单,没有难度,因为这里的分支都确定好了,就三种分支;并且在每一个结点 阅读详情

Nightmare

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 91   Accepted Submission(s) : 59
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb explodes. The initial exploding time of the bomb is set to 6 minutes. To prevent the bomb from exploding by shake, Ignatius had to move slowly, that is to move from one area to the nearest area(that is, if Ignatius stands on (x,y) now, he could only on (x+1,y), (x-1,y), (x,y+1), or (x,y-1) in the next minute) takes him 1 minute. Some area in the labyrinth contains a Bomb-Reset-Equipment. They could reset the exploding time to 6 minutes.

Given the layout of the labyrinth and Ignatius' start position, please tell Ignatius whether he could get out of the labyrinth, if he could, output the minimum time that he has to use to find the exit of the labyrinth, else output -1.

Here are some rules:
1. We can assume the labyrinth is a 2 array.
2. Each minute, Ignatius could only get to one of the nearest area, and he should not walk out of the border, of course he could not walk on a wall, too.
3. If Ignatius get to the exit when the exploding time turns to 0, he can't get out of the labyrinth.
4. If Ignatius get to the area which contains Bomb-Rest-Equipment when the exploding time turns to 0, he can't use the equipment to reset the bomb.
5. A Bomb-Reset-Equipment can be used as many times as you wish, if it is needed, Ignatius can get to any areas in the labyrinth as many times as you wish.
6. The time to reset the exploding time can be ignore, in other words, if Ignatius get to an area which contain Bomb-Rest-Equipment, and the exploding time is larger than 0, the exploding time would be reset to 6.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case starts with two integers N and M(1<=N,Mm=8) which indicate the size of the labyrinth. Then N lines follow, each line contains M integers. The array indicates the layout of the labyrinth.
There are five integers which indicate the different type of area in the labyrinth:
0: The area is a wall, Ignatius should not walk on it.
1: The area contains nothing, Ignatius can walk on it.
2: Ignatius' start position, Ignatius starts his escape from this position.
3: The exit of the labyrinth, Ignatius' target position.
4: The area contains a Bomb-Reset-Equipment, Ignatius can delay the exploding time by walking to these areas.

Output

For each test case, if Ignatius can get out of the labyrinth, you should output the minimum time he needs, else you should just output -1.

Sample Input

3
3 3
2 1 1
1 1 0
1 1 3
4 8
2 1 1 0 1 1 1 0
1 0 4 1 1 0 4 1
1 0 0 0 0 0 0 1
1 1 1 4 1 1 1 3
5 8
1 2 1 1 1 1 1 4 
1 0 0 0 1 0 0 1 
1 4 1 0 1 1 0 1 
1 0 0 0 0 3 0 1 
1 1 4 1 1 1 1 1 

Sample Output

4
-1

13

初始时间为6,地图中会有时间重置器,注意只要在搜索的过程中碰到时间重置器后将其变为强就好了

#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
int ma[10][10];
int xx,yy;
int x1[4]={1,0,0,-1};
int y1[4]={0,1,-1,0};
struct point{
    int x;
    int y;
    int t;
    int bs;
};
bool check(int x,int y){
    if(ma[x][y]==0||x<1||x>xx||y<1||y>yy)
    return 0;
    return 1;
}
int bfs(int xs,int ys){
    queue<point> lss;
    point tt;
    tt.x=xs;
    tt.y=ys;
    tt.t=6;
    tt.bs=0;
    lss.push(tt);
    while(!lss.empty()){
        tt=lss.front();
        lss.pop();
        if(ma[tt.x][tt.y]==3&&tt.t>0)
        {
            return tt.bs;
        }
        if(ma[tt.x][tt.y]==4&&tt.t>0)
        {
            tt.t=6;
            ma[tt.x][tt.y]=0;
        }
        if(tt.t==1)continue;
        for(int i=0;i<4;i++){
            int xxx=tt.x+x1[i];
            int yyy=tt.y+y1[i];
            
            if(check(xxx,yyy))
            {point hh;
            hh.x=xxx;
            hh.y=yyy;
            hh.t=tt.t-1;
            hh.bs=tt.bs+1;
                lss.push(hh);
            }
        }
    }
    return -1;
}
int main(){
  int n;
  scanf("%d",&n);
  while(n--){
     scanf("%d%d",&xx,&yy);
     int i,j;
     int X,Y;
     for(i=1;i<=xx;i++)
     {
         for(j=1;j<=yy;j++)
         {
             scanf("%d",&ma[i][j]);
             if(ma[i][j]==2)
             {
                 X=i;
                 Y=j;
             }
         }
     }
     int ans=bfs(X,Y);
     cout<<ans<<endl;
  }
return 0;
}


BFS hdu 1072 Nightmare http://acm.hdu.edu.cn/showproblem.php?pid=1072 #include #include #include #include #include /* 求最短步数,BFS,剪枝的时候注意,这里有时间的限制,故用vis[x][y][time]三维数组 来标记 */ using namespace std; struct node { int x 阅读详情

相关推荐

Qt qcustomplot第三方绘图工具绘制简单频谱图

Qt qcustomplot第三方绘图工具绘制简单频谱图

HDU 1072(BFS)

Nightmare<br />Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)<br />Total Submission(s): 1960    Accepted Submission(s): 956<br /><br />Problem DescriptionIgnatius had a nightmare last night. He found himself in a labyri

-- bird -- 810

抖音短连接v.douyin.com/xxx 如何生成?

最近公司有个需求,在抖音里如何宣传自己的网站,并且不要有拦截域名的提示,截图如下。 通过ida反编译抖音的app后,将下载后的ipa文件用解压缩软件(如7zip等)解压,从解压后的目录Payload/Aweme.app/找到Aweme可执行文件,拖入ida进行反编译,ida可以检测objective-c语法。 然后进入主题,既然是聊天发消息,就尝试在ida里搜索"message",看看能否找到对...

kakuapi的博客 3万+

hdu 1072 解题报告 ---- Nightmare

hdu 1072 解题报告 ---- Nightmare 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1072 这题是一个BFS的题目,是对于每个结点进行四个方向的循环遍历行走。       要点:如果该结点被第二次访问,则需判断该点前次标记的剩余时间是否小于当前进入后时间,若不是则不走该点,防止无限循环。 画模拟图可知其行走形式是从起点向外

落天雨、、 1139

H2O到OmniH2O细节解读,人形机器人遥操作的技术演进与哲学

摘要:CMU何泰然团队相继发表的H2O和OmniH2O论文为人形机器人遥操作领域带来突破。H2O首创Sim-to-Data方法,通过形态/动作重定向和特权筛选处理人类动作数据,PPO算法实现基础控制。OmniH2O改进为教师-学生蒸馏框架,采用DAgger算法增强泛化能力,并消除对线速度输入的依赖。这两项工作从概念验证到工程落地,建立了一套完整的动作学习范式,为具身智能研究提供了重要参考。

CyanNoah的博客 1400

STM32F407 UART4串口DMA收发实战:告别频繁中断,用空闲中断+DMA搞定不定长数据

本文详细介绍了STM32F407 UART4串口结合DMA和空闲中断实现高效不定长数据收发的实战方案。通过DMA硬件级数据搬运和空闲中断智能帧检测,显著降低CPU占用率,提升通信效率,适用于工业传感器数据采集和智能设备通信场景。

weixin_42631411的博客 161

HDU【1072】Nightmare

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1072 分析 这道题目涉及到bfs+回溯,所以不能像一般的bfs将经过的点进行标记,因为题目中炸弹的爆炸时长为6,所以只需要将经过的4的点进行标记,其他已经走过的点也只是在4这个点上最多回溯6步。 #include<iostream> #include<cstdio> #incl...

yj8023xx的博客 276

牛顿法vs高斯牛顿法vs LM算法:三行代码说清核心区别(附性能对比表格)

本文通过对比牛顿法、高斯牛顿法和LM算法的核心迭代代码,揭示了三者在非线性最小二乘优化中的本质区别。LM算法通过引入阻尼因子,在高斯牛顿法的快速收敛与梯度下降的稳定性之间取得平衡,成为工程实践中鲁棒性最强的首选。文章还提供了清晰的性能对比表格,帮助开发者根据初始估计和问题性质快速选择合适算法。

weixin_29062255的博客 429

HDU1072 Nightmare(dfs)

题意:在一个n*m的迷宫,有一个炸弹,倒计时是6分钟,Ignatius 需要逃出去,0代表墙不能走,1代表空地,2代表初始位置,3代表目的地,4代表炸弹重置点,达到这个点后炸弹时间会被重置为6分钟,重置次数不限。每次只能向上、下、左、右移动,移动一格需要一分钟,每一点可以重复到达。求逃生的最短时间,不能则输出-1。还有以下规则: 1、当移动到目的地时炸弹时间刚好为0则无法逃生。 2、当移动到重

hcx11333的博客 388

Trae IDE与Playwright MCP:5分钟实现零代码网页数据抓取

网页数据抓取是数据采集和自动化处理中的基础技术,其核心原理是通过程序模拟浏览器行为,定位并提取页面中的结构化信息。传统方式依赖编写脚本处理网络请求、解析HTML和应对反爬机制,技术门槛较高。而结合AI与自动化工具的新范式,通过自然语言交互即可完成复杂操作,极大降低了技术门槛并提升了开发效率。这种技术价值在于将开发者从繁琐的编码中解放,使其更专注于数据分析和业务逻辑。在数据监控、市场调研、竞品分析等应用场景中,快速获取网页数据是关键需求。本文以Trae IDE集成Playwright MCP为例,演示如何通过

culi3118的博客 502

YOLO11改进 | 注意力机制 | 添加SimAM注意力机制【全网独家+附完整代码】

yolo11,yolo11改进,yolo11创新,yolo11添加注意力机制

kay_545 1246

HDU-1072 Nightmare

HDU-1072 Nightmare 题目链接:HDU-1072 题目大意:2是起点,3是终点,0是墙,问能不能在6秒(走一步一秒)之内走出去,注意到达4的位置可以将秒数重置为6,0秒时不能重置时间也不能到达终点。 解题思路:bfs即可,注意对可以到达的位置能经过的次数进行限制 不然会超时 限制也不能太苛刻 毕竟有的情况还得返回来走 代码块: #include<iostream> ...

鱼头的水题之路 248

Claude Code Agents 进阶:多代理协作与任务委托

Agent 是一个独立运行的 Claude 实例,它有自己的上下文和任务焦点。│ 主 Claude ││ (协调者) ││ │ │▼ ▼ ▼│ 代码审查 │ │ 测试生成 │ │ 文档编写 ││ │ ││▼汇总结果,完成任务并行处理:多个 Agent 同时工作,提高效率任务隔离:每个 Agent 有独立的上下文专业分工:不同类型的 Agent 擅长不同任务灵活控制:可以指定运行模式、超时等参数。

gaoxiang_120的专栏 338

HDU 1072 Nightmare(BFS)

HDU 1072 Nightmare(BFS) http://acm.hdu.edu.cn/showproblem.php?pid=1072 题意:有一个N*M的迷宫,你要从起点2走到终点3,且你身上有炸弹,这个炸弹6分钟后爆炸,你在迷宫中每走一步需要1分钟,且迷宫中有重置装置(4格子),可以使得你的炸弹爆炸时间重新变为6.不过不论是你到达终点还是你到达重置装置的地方,你身上的炸弹爆炸时间一定

code 1130

【python三维深度学习】python三维点云从基础到深度学习

从三维点云基础知识到深度学习,将按照以下目录持续进行更新。更新完成的部分可以在三维点云专栏中查看。含数据与python源码。

叶子的博客 2万+

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

【HDU1072】Nightmare,思路+解题报告+代码

#include #include #include #include #include #define INPUT using namespace std; const int c0de4fun = 10; int x[4] = {1,-1,0,0}; int y[4] = {0,0,1,-1}; int maze[c0de4fun][c0de4fun]; /** Proble

c0de4fun的完美算(nei)法(he)教室-我们仍不知道,那天调用的驱动的名字。 1162

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

hdu1072 nightmare

hdu1072 nightmare ……跟hdu1242有些不同 走过的路可以返回 所以不要标记,换炸弹的倒计时限制队列的增长 #include #include #include using namespace std; int mp[10][10],m,n,Sx,Sy,Dx,Dy,flag,dir[4][2]={{0,1},{0,-1},{1,0},{-1,0

Time flies 765

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

HDU 1072 Nightmare

hdu 1072 题目大意就是一个人身上有一个炸弹,这个炸弹6分钟后爆炸,在迷宫中,0是墙,不能走; 1可以走, 2是开始位置,3是出口,4是炸弹充值装置,如果走到那个位置时,炸弹事件大于0,就会把、时间重置为 6 分钟(这里我开始理解错了,以为他获得了这个装置,可以随时使用,意思就是相当于增加6分钟);走到出口时,剩余的时间必须大于0; 这个题,用BFS,开一个结构体,记录...

aocang4831的博客 95

hdu_1072_nightmare_BFS_用时间来限定

代码来自于别人,自己写怎么都AC不过,明早一早要看的内容: //HDU1072 Nightmare //http://acm.hdu.edu.cn/showproblem.php?pid=1072 //这道题和别的bfs不一样的是它有一个还原点的设置,所以在标记用过的点时 //不能单单以坐标为标准,还要有这一点的时间 #include #include using namespace std;

Allianzcortex_Technology_Blog 418

HDU1072 Nightmare

hud 1072 Nightmare 简单的dfs迷宫问题

jw72jw的专栏 1951

hdu 1072 Nightmare

https://blog.csdn.net/sxx312/article/details/51762904 /******************************************* FileName:bfs Author:苏相学 Date:2016年6月26日15:44:37 Description:功能 Others: ***************************...

NoahCool 192

HDU 1072Nightmare

Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb e...

slience_646898的博客 321

Nightmare HDU - 1072

Nightmare Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13745    Accepted Submission(s): 6655   Problem Description Ignatius had a nightma...

zezzezzez的博客 409
上一篇: hdu 1070 milk
下一篇: hdu1078 FatMouse and Cheese
threeh20
博客等级 码龄9年 64粉丝 422原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值