题目描述

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. Promise API

    Promise API     刚刚接触promise这个东西,网上看了很多博客,大部分是讲怎么用Promise,丝毫没提怎么实现Promise. 我不甘 心,可是真去看JQuery或者Angular ...

  2. ubuntu 下交叉编译环境的搭建

    1. 安装标准的C开发环境,由于Linux安装默认是不安装的,所以需要先安装一下(如果已经安装好的话,就可以免去这一步了): #sudo apt-get install gcc g++ libgcc1 ...

  3. UVaLive 4094 WonderTeam (贪心)

    题意:有n支队伍,每两支队伍打两场比赛(主客场各一次),胜得3分,平得1分,输不得分,比赛结束之后会评选出一个梦之队, 梦之队满足以下条件:进球总数最多,胜利场数最多,丢求总数最少,三个都不能并列,求 ...

  4. VC/MFC的HDC,CDC,CWindowDC,CClientDC,CPaintDC详解:

    VC/MFC的HDC,CDC,CWindowDC,CClientDC,CPaintDC详解: 首先说一下什么是DC(设备描述表) 解:Windows应用程序通过为指定设备(屏幕,打印机等)创建一个设备 ...

  5. CQL查Cassandra条目数中的小问题

    用查询语句:SELECT count(*) FROM tablename 返回类型是ResultSet,得到tablename中所有条目数 ResultSet类型可以直接用index访问:Result ...

  6. springboot 之 controller

    添加一个testController的java 类,部分代码 注解标记这是一个controller,配置路径,自动加载配置. 注入的方式有@Autowired 和@Resource 二者的区别是 @A ...

  7. python接口自动化(三十九)- logger 日志 - 上(超详解)

    简介 Python的logging模块提供了通用的日志系统,可以方便第三方模块或者是应用使用.这个模块提供不同的日志级别,并可以采用不同的方式记录日志,比如文件,HTTP GET/POST,SMTP, ...

  8. eclipse 通过svn导入maven工程

    http://blog.csdn.net/zdnlp/article/details/7238194

  9. Sublime Text 快捷键的使用

    Sublime Text 快捷键的使用 快捷键列表(Shortcuts Cheatsheet) 我把本文出现的Sublime Text按其类型整理在这里,以便查阅. 通用(General) ↑↓←→: ...

  10. 黑马学习JavaWeb入门总结