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;
}
VPI与Matlab协同仿真:相干光通信接收端DSP算法全解析 本文详细解析了如何利用VPI与Matlab协同仿真,构建完整的相干光通信接收端DSP算法处理闭环。重点介绍了从VPI导出数据后,在Matlab中实现时钟恢复、偏振解复用和载波相位估计等核心算法的步骤与原理,并阐述了如何通过误码率计算完成仿真验证,为相干光通信系统算法研究与验证提供了高效实用的方法。 阅读详情

相关推荐

多智能体协作的本质是中介者模式,不是多开Agent

多智能体系统并非简单启动多个Agent实例,而是一种受控的、可验证的动态交互过程。其核心原理在于解耦Agent间直接依赖,通过中央中介者统一管理任务分发、协议转换、状态协调与故障兜底。这种架构显著提升系统的可观测性、容错性与可维护性,技术价值体现在强一致性保障(如金融订单原子操作)与灵活自治平衡(如边缘设备轻量协同)。典型应用场景包括电商客服协同、工业巡检调度、飞书/微信多渠道智能服务等。OpenClaw与Hermes Agent正是这一范式的工程落地代表,分别体现强中介与弱中介两种演进路径。

weixin_34151004的博客 359

P2895 [USACO08FEB]Meteor Shower S

在流星雨的田野里穿梭

qq_43034907的博客 700

高通 Gen AI 推理扩展 (GENIE)(5):实战指南与Engine API深度解析

本文深入解析高通Gen AI推理扩展(GENIE)的Engine API核心功能与实战应用,涵盖引擎实例化、多引擎动态切换、性能调优及跨平台部署等关键技巧。通过详细代码示例和性能数据,帮助开发者高效利用GENIE进行AI推理,提升应用性能与稳定性。

weixin_29065959的博客 465

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

直击痛点:VS2015离线安装报错“安装包丢失或损坏”的根源分析与精准修复

本文深入剖析了Visual Studio 2015离线安装时出现“安装包丢失或损坏”报错的根本原因,指出问题核心在于安装程序固化的临时路径查找逻辑。文章提供了一步到位的精准修复方案,通过将ISO镜像中的完整packages文件夹复制到安装程序指定的临时路径,即可无需联网、无需操作证书直接解决问题,并对比分析了其他常见方法的局限性。

weixin_27734811的博客 357

OpenHarmony自定义Launcher

OpenHarmony源码版本:4.0release开发板:DAYU / rk3568DevEco Studio版本:4.0.0.600切换分支为OpenHarmony-4.0-Release,并下载源码。

Abner_Crazy的博客 1630

每日一题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

PCB设计AD规则设置(按照嘉立创设置)

按照嘉立创的相关加工能力进行设置: 1.Hole Size(钻孔孔径) 嘉立创要求钻孔孔径在0.2-6.3mm,并给了公差(如下图给出了钻孔孔径和公差) 规则设置位置:Manufacturing->Hole Size,这里就改一下数值,最小设置为0.2mm,最大设置为6.3mm 2.Width(线宽) 嘉立创要求线宽多层板双层板最小为3.5mil,单双层板最小为5mil(如下图给出了线宽) 规则设置位置:Routing->Width,我目前只画过双层板,按我的设置如下,最小的线宽设置为10

subtitle_的博客 4万+

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

安卓开发工程师在车载项目中的角色与技术实践

本文全面探讨了安卓开发工程师在车载项目中的关键角色,重点分析了技术栈(Kotlin/Java/Gradle)、岗位职责和任职要求。文章详细解读了车载安卓开发的核心技能,包括架构设计、性能优化和缺陷修复,并提供了20个针对性面试问题及答案。特别强调了车载环境的特殊需求,如硬件集成、安全认证和实时性要求。通过技术深度与实践案例的结合,为开发者和企业提供了从需求分析到系统优化的完整指导,旨在提升车载安卓开发的专业水平和招聘效率。

郑伟强dev的专栏 131

YOLOv11【第三章:高阶应用与落地篇·第1节】一文搞懂,YOLOv11-Seg 实例分割:Mask 原型生成与系数预测原理解析!

🏆 本文收录于专栏 《YOLOv11实战:从入门到深度优化》。本专栏围绕 YOLOv11 的改进、训练、部署与工程优化 展开,系统梳理并复现当前主流的 YOLOv11 实战案例与优化方案,内容目前已覆盖 分类、检测、分割、追踪、关键点、OBB 检测 等多个方向。

**My Coding Family** 1248

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

Java调用OpenDDS(2)-理解OpenDDS自带的Messager示例

理解Messenger

zhangzl419 1660

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

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Poj3669 meteor shower bfs

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

Na_OH的博客 530

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

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

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

一枝之栖 355

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

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、付费专栏及课程。

余额充值