洛谷 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 ...
随机推荐
- eclipse修改workspace
Eclipse是一款很强的Java IDE,我们在开始的时候,往往设定了默认的workspace,当用久在之后,我们可能要去更改一下workspace的位置,但是在启动的时候已经不会显示更改了.下面有 ...
- ant错误 reference classes not found
使用ant提示reference classes not found错误 原因是 里面的一些属性的值要用on或者yes或者off或者no..用成其他,例如true,false的话就会有这个提示..
- Go中函数作为值、类型传递。
在Go中函数也是一种变量,我们可以通过type来定义它,它的类型就是所有拥有相同的参数,相同的返回值的一种类型 type typeName func(input1 inputType1 , input ...
- Linux Ubuntu下Jupyter Notebook的安装
Jupyter Notebook, 以前又称为IPython notebook,是一个交互式笔记本, 支持运行40+种编程语言. 可以用来编写漂亮的交互式文档. 安装步骤: pip install - ...
- POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...
- Linux系统下使用split命令分割大文件 (转载)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://snailwarrior.blog.51cto.com/680306/140531 ...
- windows如何定时关闭一个程序
方法一其实系统本身有这项功能的,打开记事本,将以下内容保存为.bat文件(将下面cmd.exe的名字改成你的音乐播放软件的exe名)@echo offTASKKILL /F /IM cmd.exe / ...
- Mathematics Base - Tensor
以下是我对张量的理解,备注是具体解释,Xmind导出的图片没法显示出来,主要还是将张量间的关系画出来,方便理解. 图1 张量
- 教妹学 Java:晦涩难懂的泛型
00.故事的起源 “二哥,要不我上大学的时候也学习编程吧?”有一天,三妹突发奇想地问我. “你确定要做一名程序媛吗?” “我觉得女生做程序员,有着天大的优势,尤其是我这种长相甜美的.”三妹开始认真了起 ...
- LuoguP2323 [HNOI2006]公路修建问题 【最小生成树+二分】By cellur925
题目大意:给你\(n\)个点,\(m\)条边,每条边上有两个权值:一级和二级的.选\(n-1\)条边使这个图连通,并至少有\(k\)个一级边,求花费最多的一条边最小值及方案. 最大值最小,肯定会先想到 ...