POJ 3669 Meteor Shower——————bfs

【题解】POJ 3669 Meteor Shower(BFS) POJ 3669 Meteor Shower https://vjudge.net/problem/POJ-3669 题意 有一场流星雨即将到来,Bessie要找到一个安全的地方。现在已知有M颗流星,并且知道它们抵达的位置和时间,Bessi走一个单位需要一个单位时间,问到达安全位置的最短时间,如果无法到达安全位置就输出-1。 细则: 1、Bessie从起点出发,可以向上下左右四个方向行走。 ... 阅读详情

Meteor Shower

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 31235 Accepted: 8037
Description
Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to a safe location (one that is never destroyed by a meteor) . She is currently grazing at the origin in the coordinate plane and wants to move to a new, safer location while avoiding being destroyed by meteors along her way.

The reports say that M meteors (1 ≤ M ≤ 50,000) will strike, with meteor i will striking point (Xi, Yi) (0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 300) at time Ti (0 ≤ Ti ≤ 1,000). Each meteor destroys the point that it strikes and also the four rectilinearly adjacent lattice points.

Bessie leaves the origin at time 0 and can travel in the first quadrant and parallel to the axes at the rate of one distance unit per second to any of the (often 4) adjacent rectilinear points that are not yet destroyed by a meteor. She cannot be located on a point at any time greater than or equal to the time it is destroyed).

Determine the minimum time it takes Bessie to get to a safe place.

Input

  • Line 1: A single integer: M
  • Lines 2…M+1: Line i+1 contains three space-separated integers: Xi, Yi, and Ti

Output

  • Line 1: The minimum time it takes Bessie to get to a safe place or -1 if it is impossible.

Sample Input
4
0 0 2
2 1 2
1 1 2
0 3 5
Sample Output
5

Source
USACO 2008 February Silver


/*--------- hongjie ----------*/
// #include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#include<vector>


using namespace std;
typedef long long ll;
typedef pair<int ,int> P;

const int INF  = 0x3f3f3f3f;
const int MAXN = 300+20;
const int N = 300;

struct node{
        int x,y,step;
        node(){};
        node(int _x, int _y, int _step) {
                x = _x;
                y = _y;
                step = _step;
        }
        bool operator < (const node &b)const {
                return step > b.step;
        }

}e;

int maze[MAXN][MAXN];
int vis[MAXN][MAXN];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int step,minStep = INF;


bool check(int x,int y) {
        // return x>=0 && y>=0  && y<=N && x<=N && !vis[x][y];
        return x>=0 && y>=0  && !vis[x][y];
}

void bfs() {
        memset(vis,0,sizeof(vis));
        priority_queue<node> que;
        e.x = 0;
        e.y = 0;
        e.step = 0;
        vis[0][0] = 1;
        que.push(e);
        while(!que.empty()) {
                e = que.top(); que.pop();
                if(maze[e.x][e.y] == INF) {
                        minStep = min(minStep, e.step);
                        break;
                }
                for(int i=0;i<4;++i) {
                        int nx = e.x + dx[i];
                        int ny = e.y + dy[i];
                        if(check(nx,ny) && (maze[nx][ny]==INF || e.step + 1 < maze[nx][ny])) {
                                node ex;
                                ex.x = nx; ex.y = ny; ex.step = e.step+1;
                                que.push(ex);
                                vis[nx][ny] = 1;
                        }
                }
        }

}

int main(){
        // freopen("../in.txt","r",stdin);
        // freopen("../out.txt","w",stdout);
        int m;

        while(~scanf("%d",&m)) {
                memset(maze,0x3f,sizeof(maze));
                for(int i=0;i<m;++i) {
                        int x, y, t;
                        scanf("%d %d %d",&x,&y,&t);
                        maze[x][y]   = min(maze[x][y],   t);
                        maze[x+1][y] = min(maze[x+1][y], t);
                        if(x>=1)
                                maze[x-1][y] = min(maze[x-1][y], t);
                        maze[x][y+1] = min(maze[x][y+1], t);
                        if(y>=1)
                                maze[x][y-1] = min(maze[x][y-1], t);
                }

                minStep = INF;
                bfs();
                if(minStep==INF)        minStep = -1;
                printf("%d\n",minStep);
        }
        return 0;
}
CTS实战:如何用set_sense优化时钟树平衡(附ICC2避坑指南) 本文深入探讨了在时钟树综合(CTS)中,如何正确使用`set_sense`命令优化时钟树平衡,并对比了其与`set_disable_timing`的本质区别。通过实战案例详细解析了`-stop_propagation`和`-clock_leaf`参数的应用场景,并提供了ICC2工具中的关键避坑指南,帮助后端工程师精准控制时钟拓扑,避免时序分析漏洞。 阅读详情

相关推荐

ABB机器人与西门子PLC、工业相机联合实现无序抓取的完整调试方案

将此方案导入系统后,逐步执行调试,确保各环节信号正常触发,即可实现高效无序抓取!

CHUXUEZHE8210的博客 1993

P2895 [USACO08FEB]Meteor Shower S

在流星雨的田野里穿梭

qq_43034907的博客 700

SRC漏洞挖掘实战指南:从零入门到月入过万的网络安全副业

网络安全的核心在于识别和修复系统缺陷,其中逻辑漏洞与信息泄露是常见的安全风险。其原理在于应用程序在业务逻辑设计或数据处理过程中存在缺陷,导致未授权访问或敏感数据暴露。掌握这些技术对于构建安全的应用体系至关重要,不仅能有效防范攻击,也为安全研究人员提供了将技术能力变现的合法途径。在漏洞赏金(Bug Bounty)和SRC(安全应急响应中心)等应用场景中,白帽子通过系统化的测试方法,挖掘此类漏洞,既能获得经济回报,又能积累宝贵的实战经验。本文聚焦于逻辑漏洞与信息泄露的实战挖掘技巧,为初学者提供清晰的入门路径和效

weixin_28568819的博客 349

A - Meteor Shower的解答

A - Meteor Shower Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to fi...

Sunshine_H的帅气博客 466

多周期路径约束(set_multicycle_path )

1.由慢到快的多周期约束 如下图所示,发射时钟周期是接受时钟周期的4倍。默认情况下,按照1T原则来进行静态时序分析和布局布线的。即建立时间是在发射沿后的第一个捕获沿检查,而保持时间是同一时刻下源时钟和捕获时钟的触发边沿下检查的(建立时间检查边沿的前一个触发沿)。 但是这样导致的问题就是该路径过于苛刻,为了满足这条路径的要求,不得不放弃其他路径。或者根本没办法保证这个默认的约束。总之最终造成...

Arist. 5506

游戏大厂状态同步与帧同步技术全解析——让虚拟世界万物协同的“时间齿轮”

本文深入解析了大厂游戏开发中的两种核心同步技术:状态同步和帧同步。状态同步适合大型MMO和FPS游戏,由服务端计算并广播世界状态;帧同步则通过统一操作输入实现MOBA和RTS游戏的绝对公平。文章详细比较了两者的差异、适用场景和底层实现原理,并揭秘了《王者荣耀》《PUBG》等热门游戏的同步机制。同时探讨了本地预测、延迟补偿、防作弊等关键技术,以及未来AI和云游戏带来的同步新挑战,为开发者提供了全面的技术参考和实践指南。

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 919

每日一题4.14 P2895 [USACO08FEB]Meteor Shower

P2895 [USACO08FEB]Meteor Shower S 题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her s...

u014567353的博客 476

手把手教你使用ConvNeXt训练自己数据集和推理,ConvNeXt模型训练(CVPR 2022),一个能挑战 Vision Transformer 的卷积神经网络,含完整代码和数据集

手把手教你使用ConvNeXt训练自己数据集和推理,ConvNeXt模型训练(CVPR 2022),一个能挑战 Vision Transformer 的卷积神经网络,含完整代码和数据集

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 1450

BFS---陨石坠落

https://www.luogu.com.cn/problem/P2895 题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to a safe locatio

zw201909250425的博客 443

高温环境下(100℃以上)相机的几种保障方案

高温环境下相机保障措施摘要:针对120℃以上高温环境,相机需采取多重防护:1.散热设计采用金属机身、散热鳍片或风扇;2.关键部件选用耐高温材料(铝合金、特种玻璃);3.电子元件需军规级芯片并做三防处理;4.建议外接电源或耐高温电池。工业相机(如FLIR A655sc、Basler ace)及特种机型(Ximea xiQ)具备高温适应性,普通相机可加装隔热套件配合冷却系统。选择时需关注传感器信噪比和全局快门性能,并设置温度监控保护机制。注意高温会加速设备老化,需定期检测维护。(149字)

start_up_go的博客 1585

结构优化软件:OptiStruct_(11).拓扑优化

在OptiStruct中,设计空间可以通过定义设计区域来实现。设计区域是结构中可以进行材料变化的部分。几何区域:通过几何选择工具选择特定的区域。网格区域:通过网格选择工具选择特定的单元。假设我们有一个简单的梁结构模型,网格文件为beam.fem。我们希望在梁的中部进行拓扑优化,以减轻重量并保持刚度。

kkchenjj的博客 1367

POJ3669-Meteor Shower-BFS

原题链接 Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18098 Accepted: 4704 DescriptionBessie hears that an extraordinary meteor shower is coming; reports say tha

HowieMen的博客 400

AUTOSAR从入门到精通-汽车电子电气架构(EEA)(二)

需求的传递并非完全是瀑布式的单向传递,而是双向的,只有被下游接受了的需求才是有效的需求,而且,下游是可以反向对上游提出需求的。当街区的设计完成之后,接下来要做的就是每栋建筑的详细设计,建筑的设计者发布的图纸中规定了房屋的主要结构、所在位置与周边环境的相互关系,以及屋中各种组件的位置与相互之间结合的关系,比如砖混结构、房屋的具体位置和朝向、卧室与客厅的相对位置与尺寸、马桶在卫生间中的位置等,还会对各种建筑材料的选取原则给出具体的标准,比如水泥的标号,钢筋的型号,各种电线的等级要求等等。

getusushu的博客 372

poj3669 Meteor Shower(BFS)

题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了。。。 1 #include<cstdio> 2 #include<cmath> 3 #include<queue> 4 #include<cstr...

dhe56357的博客 256

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Poj3669 meteor shower bfs

题目链接:http://poj.org/problem?id=3669 题目大意:女主牛在起点(0,0),天气预报说今天会下流星雨,女主牛得逃生,流星砸下来它的附近的四个格点的位置都会被毁灭,以后不能再走,女主牛每次可走在地图范围内的四个格点,问女主牛至少得走多少歩才能安全。 分析:这个题目至少,明显是bfs,但又和以前的bfs不一样,唔。。。后来看了别人的结题报告才明白要自己够遭地图,先构建

Na_OH的博客 530

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

【和小安一起刷题】POJ3669 Meteor Shower ----广度优先搜索(BFS)

01、题目描述 小伙伴们大家好,这里是和 【和小安一起刷题 】 系列栏目,今天我们要解决的是一道广搜题目——POJ3669 Meteor Shower。在解决题目前,你需要知道BFS的基本框架和C++< queue >库的简单使用。 题目链接: POJ3669 Meteor Shower. 题目描述:一场流星雨即将袭来,流星会对每个击中的地方以及其周围(上下左右四格)造成破坏。小明开始时位于(0, 0)位置,准备逃到一处不会被袭击到的地方(小明只能在第一象限内移动)。已知每移动1个单位长度需要1

一枝之栖 355

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

POJ3669Meteor Shower【BFS】

Language: Default Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11570   Accepted: 3163 Description Bessie hears that an extraordinary

走一步再走一步 770

POJ3669 Meteor Shower【BFS】

Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37006 Accepted: 9463 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxi

海岛Blog 431

[bfs] POJ 3669 Meteor Shower

题目 Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31700 Accepted: 8158 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteor...

weixin_44197056的博客 189

POJ 3669-Meteor Shower(BFS)

C - Meteor Shower Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3669 Appoint description:  System Crawler  (2016-04-28) Descr

梧桐下的四叶草 681

POJ 3669 Meteor Shower BFS

Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find he...

RPG_Zero的博客 263

BFS——Poj 3669 Meteor Shower

题目 Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18796 Accepted: 4879 Description Bessie hears that an extraordinary meteor shower is coming;...

点滴 521

[bfs] poj 3669 Meteor Shower

Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her

童凌的技术博客 685

POJ-3669 Meteor Shower BFS

http://poj.org/problem?id=3669 题意:巨大流星雨即将袭来。每个流星会对击中的地方以及周围(上下左右四格)造成破坏。Bessie开始时位于(0, 0)位置,并希望逃到一处不会被袭击到的地方(在第一象限内)。已知每移动一格需要1个时间单位,被流星破坏后的地方不能再进入。给出M个流星在T时刻击中的地方(X, Y),问Bessie能否逃到安全的地方,若能输出最短时间

ACM_10000h的专栏 1023

poj 3669 Meteor Shower 【BFS】

Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12517   Accepted: 3386 Description Bessie hears that an extraordinary meteor shower is coming

世界很大 489

BFS搜索:POJ No 3669 Meteor Shower

BFS搜索:POJ No 3669 Meteor Shower #include <iostream> #include <cstring> #include <queue> #include <cstdio> #include <cstdlib> #include <...

豆子 186
上一篇: HDU 3949 XOR——————线性基
下一篇: POJ 3050 Hopscotch——————dfs
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值