洛谷 P2895 [USACO08FEB]流星雨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 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.
输入输出样例
4
0 0 2
2 1 2
1 1 2
0 3 5
5
#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的更多相关文章
- 洛谷—— P2895 [USACO08FEB]流星雨Meteor Shower
P2895 [USACO08FEB]流星雨Meteor Shower 题目描述 Bessie hears that an extraordinary meteor shower is coming; ...
- 洛谷P2895 [USACO08FEB]流星雨Meteor Shower
题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...
- 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower 解题报告
一起来看流星雨吧(话说我还没看到过流星雨呢) 题目 Problem 小A则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽,届时将会对它撞到的一 ...
- bzoj1611 / P2895 [USACO08FEB]流星雨Meteor Shower
P2895 [USACO08FEB]流星雨Meteor Shower 给每个点标记一下能够走的最迟时间,蓝后bfs处理一下 #include<iostream> #include<c ...
- P2895 [USACO08FEB]流星雨Meteor Shower
传送门 预处理出每个位置最早被摧毁的时间,在此之前都可以走 直接dfs加个记忆化和最优性剪枝就好了 一定要注意流星的边界,如果波及到负数坐标的位置不要去考虑会RE 一定要考虑流星砸到边界的情况 如 ( ...
- 洛谷 P2895 [USACO08FEB]Meteor Shower S (BFS)
题意:你刚开始位于坐标轴的\((0,0)\)点,一共有\(m\)颗流星砸向地面,每颗流星在\(t\)时砸到\((x,y)\)点,其四周上下左右也均有波及,你每秒可以向上下左右移动一个单位,问你是否可以 ...
- 洛谷P2894 [USACO08FEB]酒店Hotel
P2894 [USACO08FEB]酒店Hotel https://www.luogu.org/problem/show?pid=2894 题目描述 The cows are journeying n ...
- 洛谷 P2894 [USACO08FEB]酒店Hotel-线段树区间合并(判断找位置,不需要维护端点)+分治
P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultur ...
- 洛谷 P2894 [USACO08FEB]酒店Hotel 解题报告
P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultur ...
随机推荐
- Do not have XXX handler in current page
这种错误没有什么技术含量,也很容易解决. 一般就是wxml里面的button/form之类的,你用bindtap/bindsubmit给它绑了一个XXX函数,但是呢,你没有在相关js页面里面定义这个函 ...
- C++11之lambda表达式应用
应用 foreach语句中 #include <time.h> #include <algorithm> using namespace std; void func(int ...
- 解码H264文件的一些基础知识
这段时间一直在进行编写H264文件的解析类,因此对于H264文件的格式有了初步的了解,官方文档也看了个大概.这篇文章主要是总结了一些为解码H264文件而需要的一些前期知识,话不多说,下面是干货,有些是 ...
- Weekly Contest 112
945. Minimum Increment to Make Array Unique Given an array of integers A, a move consists of choosin ...
- git (Linux安装及使用教程)
查看当前服务器是否有安装git git --version 如果有,那么查看版本号,是否是你想要的或最新的版本 如果不是自己想要的版本,那么执行以下命令可卸载当前版本 yum remove git 卸 ...
- 乐字节-Java8核心特性实战之Stream(流)
说起流,我们会想起手机 ,电脑组装流水线,物流仓库商品包装流水线等等.如果把手机 ,电脑,包裹看做最终结果的话,那么加工商品前的各种零部件就可以看做数据源,而中间一系列的加工作业操作,就可以看做流的处 ...
- react父组件调用子组件方法
把子组件的参数回传到父组件中,并且赋值给子组件的一个实例方法. 参考React中文网: http://www.css88.com/react/docs/refs-and-the-dom.html im ...
- JS高级学习历程-12
冒充继承 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/T ...
- B.DongDong认亲戚
链接:https://ac.nowcoder.com/acm/contest/904/B 题意: DongDong每年过春节都要回到老家探亲,然而DongDong记性并不好,没法想起谁是谁的亲戚(定义 ...
- IIS服务器访问网站出现403错误的解决方法
最近用织梦做了一个网站,因为织梦会在一个文件夹中生成网站的静态页面,而我们单击某个栏目时,一般程序都是直接去寻找该文件夹中的index.html文件的,当服务器中默认的索引文件不包括index.htm ...