题目描述

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

题目大意:从(0,0)出发,每个点在一定时间内会被炸,求逃生的最短时间。
题解:预处理每个点被炸时间,bfs
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; int n,map[][],dis[][];
int mx[]={,,-,},
my[]={,,,-};
struct node{
int x,y;
};
queue<node>q; int main(){
scanf("%d",&n);
memset(map,0x3f,sizeof(map));
for(int i=;i<=n;i++){
int x,y,t;
scanf("%d%d%d",&x,&y,&t);
map[x][y]=min(map[x][y],t);
for(int j=;j<;j++){
int xx=x+mx[j],yy=y+my[j];
if(xx<||yy<)continue;
map[xx][yy]=min(map[xx][yy],t);
}
}
memset(dis,0x3f,sizeof(dis));
dis[][]=;node a;a.x=;a.y=;
q.push(a);
while(!q.empty()){
node now=q.front();q.pop();
if(map[now.x][now.y]==0x3f3f3f3f){
cout<<dis[now.x][now.y];
return ;
}
int x=now.x,y=now.y;
for(int i=;i<;i++){
int xx=x+mx[i],yy=y+my[i];
if(xx<||yy<||map[xx][yy]<=dis[x][y]+)continue;
if(dis[xx][yy]<=dis[x][y]+) continue;
if(dis[xx][yy]>=dis[x][y]+){
dis[xx][yy]=dis[x][y]+;
node b;b.x=xx;b.y=yy;
q.push(b);
}
}
}
puts("-1");
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. 自定义列表数据自动循环向下滚动view(类似于通知通报消息)

    首先申明,这个自定义View不是本人写的,大神写的,本人仅限学习一级研究使用 直接上代码吧!后面我再解释一遍 package com.egojit.android.gcoa.views; import ...

  2. Aeroplane chess(简单概率dp)

    Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...

  3. EasyDSS+EasyNVR实现幼儿园直播/工地直播等分权限观看直播视频的功能

    在EasyNVR互联网直播服务器使用说明书中有关于EasyNVR分组的介绍: "EasyNVR的功能定位就是为视频应用层输出视频设备接入/标准视频输出的能力平台层,只做基础的视频通道接入.视 ...

  4. js的new到底干了啥 -

    javascript通过new操作符构建一个对象的步骤 <Javascript高级程序设计>的解释: 创建一个对象 将构造函数的作用域赋给新对象(把新对象作为构造函数的调用上下文,也就是t ...

  5. oracle img 导入dmp文件

    1.新建表空间 因为我们导出的数据表的表空间不一定是USERS, 假如说是:FQDB 新建表空间SQL语句 create tablespace FQDB datafile 'c:\FQDB.dbf' ...

  6. ibatis实现Iterate的使用 (转)

    <iterate         property="" /*可选,              从传入的参数集合中使用属性名去获取值,              这个必须是一 ...

  7. struts2 封装获取表单数据的方式

    一.属性封装 1.在action中设置成员变量,变量名与表单中的name属性值相同 2.生成变量的set方法 实例 获取用户输入的用户名和密码 jsp页面 java代码 二.模型驱动(常用) 1.ac ...

  8. 安装了包,pycharm却提示找不到包

    这段时间,我爬虫爬到了一个论坛的数据,有个分析需要知道他的字符编码,因此使用到了 chardet,我在终端很顺利的安装了这个,但是在pycharm里使用的时候老是提示有错误,向下面这样: 其实这个是因 ...

  9. springcloud zuul 使用zuulfilter 修改请求路径和响应头

    最近做项目有一个需求:一个网盘系统,文件存放在分布式文件系统中,之前的文件下载统一走的文件下载服务,现在需要在单文件下载的时候不需要走文件下载服务,而是直接访问文件系统上的路径,响应的时候修改响应头, ...

  10. Write 语句

    ABAP Write 语句 转载▼http://blog.sina.com.cn/s/blog_5ccd375b0100ghhi.html   1.Write 叙述 ABAP/4 用来在屏幕上输出数据 ...