题目描述

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.

牛去看流星雨,不料流星掉下来会砸毁上下左右中五个点。每个流星掉下的位置和时间都不同,求牛能否活命,如果能活命,最短的逃跑时间是多少?

输入输出格式

输入格式:

  • Line 1: A single integer: M

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

输出格式:

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

输入输出样例

输入样例#1:

4
0 0 2
2 1 2
1 1 2
0 3 5
输出样例#1:

5
 
 
bfs
#include <cstring>
#include <cstdio>
#define N 505
int f[N<<][],l=,r=,m,G[N<<][N<<],fx[]={,,-,},fy[]={,-,,};
bool vis[N<<][N<<];
inline int min(int a,int b) {return a>b?b:a;}
void init(int x,int y,int t)
{
G[x][y]=G[x][y]==-?t:min(G[x][y],t);
for(int i=;i<;++i)
{
int tx=x+fx[i],ty=y+fy[i];
if(tx>=&&ty>=) G[tx][ty]=G[tx][ty]==-?t:min(G[tx][ty],t);
}
}
int main()
{
scanf("%d",&m);
memset(G,-,sizeof(G));
for(int x,y,t,i=;i<=m;++i)
{
scanf("%d%d%d",&x,&y,&t);
init(x,y,t);
}
f[++r][]=;
f[r][]=;
vis[][]=;
for(;l<r;)
{
int nowx=f[++l][],nowy=f[l][];
for(int i=;i<;++i)
{
int tx=nowx+fx[i],ty=nowy+fy[i];
if(G[tx][ty]==-&&tx>=&&ty>=)
{
printf("%d\n",f[l][]+);
return ;
}
if(tx>=&&ty>=&&!vis[tx][ty]&&G[tx][ty]>f[l][]+)
{
vis[tx][ty]=;
f[++r][]=tx;
f[r][]=ty;
f[r][]=f[l][]+;
}
}
}
printf("-1\n");
return ;
}
 

洛谷 P2895 [USACO08FEB]流星雨Meteor Shower的更多相关文章

  1. 洛谷—— P2895 [USACO08FEB]流星雨Meteor Shower

    P2895 [USACO08FEB]流星雨Meteor Shower 题目描述 Bessie hears that an extraordinary meteor shower is coming; ...

  2. 洛谷P2895 [USACO08FEB]流星雨Meteor Shower

    题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...

  3. 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower 解题报告

    一起来看流星雨吧(话说我还没看到过流星雨呢) 题目 Problem 小A则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽,届时将会对它撞到的一 ...

  4. bzoj1611 / P2895 [USACO08FEB]流星雨Meteor Shower

    P2895 [USACO08FEB]流星雨Meteor Shower 给每个点标记一下能够走的最迟时间,蓝后bfs处理一下 #include<iostream> #include<c ...

  5. P2895 [USACO08FEB]流星雨Meteor Shower

    传送门 预处理出每个位置最早被摧毁的时间,在此之前都可以走 直接dfs加个记忆化和最优性剪枝就好了 一定要注意流星的边界,如果波及到负数坐标的位置不要去考虑会RE 一定要考虑流星砸到边界的情况 如 ( ...

  6. 洛谷 P2895 [USACO08FEB]Meteor Shower S (BFS)

    题意:你刚开始位于坐标轴的\((0,0)\)点,一共有\(m\)颗流星砸向地面,每颗流星在\(t\)时砸到\((x,y)\)点,其四周上下左右也均有波及,你每秒可以向上下左右移动一个单位,问你是否可以 ...

  7. 洛谷P2894 [USACO08FEB]酒店Hotel

    P2894 [USACO08FEB]酒店Hotel https://www.luogu.org/problem/show?pid=2894 题目描述 The cows are journeying n ...

  8. 洛谷 P2894 [USACO08FEB]酒店Hotel-线段树区间合并(判断找位置,不需要维护端点)+分治

    P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultur ...

  9. 洛谷 P2894 [USACO08FEB]酒店Hotel 解题报告

    P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultur ...

随机推荐

  1. unique()函数

    unique()是c++里面的一个去重函数,包含在<iostream>中. 该函数将重复的元素移至容器的末尾,返回的为前面的无重复项的尾地址. 由于返回的是地址,所以经常需要转换为数值使用 ...

  2. 2-3 Flutter开发环境与iOS开发环境设置(Mac)

    Mac下环境搭建 先不看了 都是Mac下的环境搭建

  3. 世界虽大,但没有破不了的wifi

    附加知识: 无线网卡的几种常见工作模式(mode)有: master  managed monitor ad-hoc ... 1. [master] 这种模式是常见的AP模式,无线模块本身作为wifi ...

  4. UVa 10534 Wavio Sequence (LIS+暴力)

    题意:给定一个序列,求一个最长子序列,使得序列长度为奇数,并且前一半严格递增,后一半严格递减. 析:先正向和逆向分别求一次LIS,然后再枚举中间的那个数,找得最长的那个序列. 代码如下: #pragm ...

  5. Gym - 100851A Adjustment Office(O(1)求行列和)

    Adjustment Office Gym - 100851A 2       3       4 3       4       5 4       5       6 n<=10^6,q&l ...

  6. MVC动态生成的表单:表单元素比较多 你就这样写

    MVC动态生成的表单:表单元素比较多 你就这样写: public ActionResult ShoudaanActionResult(FormCollection from,T_UserM user) ...

  7. Swoole HTTP 的应用

    目录 概述 代码 小结 扩展 概述 这是关于 Swoole 学习的第四篇文章:Swoole HTTP 的应用. 第三篇:Swoole WebSocket 的应用 第二篇:Swoole Task 的应用 ...

  8. Python绘制正态分布曲线

      使用Python绘制正态分布曲线,借助matplotlib绘图工具: \[ f(x) = \dfrac{1}{\sqrt{2\pi}\sigma}\exp(-\dfrac{(x-\mu)^2}{2 ...

  9. uoj#386. 【UNR #3】鸽子固定器(乱搞)

    传送门 题解 //minamoto #include<bits/stdc++.h> #define R register #define ll long long #define fp(i ...

  10. ios 类似淘宝评论星星功能

    创建星星视图: //星星 _myview = [[UIView alloc]initWithFrame:CGRectMake(95, 5, 200, 50)]; UIPanGestureRecogni ...