洛谷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 题目大意:从(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的更多相关文章
- 洛谷—— 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 ...
随机推荐
- I2C驱动详解
I2C讲解: 在JZ2440开发板上,I2C是由两条数据线构成的SCL,SDA:SCL作为时钟总线,SDA作为数据总线:两条线上可挂载I2C设备,如:AT24C08 两条线连接ARM9 I2C控制器, ...
- COGS 1507. [IOI2000]邮局
1507. [IOI2000]邮局 ★☆ 输入文件:postoffice.in 输出文件:postoffice.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] ...
- 【BZOJ1513】[POI2006]Tet-Tetris 3D 二维线段树
[BZOJ1513][POI2006]Tet-Tetris 3D Description Task: Tetris 3D "Tetris" 游戏的作者决定做一个新的游戏, 一个三维 ...
- windy数(简单数位DP)
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 6306 Solved: 2810[Submit][Sta ...
- SuperAgent使用文档
SuperAgent是一个轻量级.灵活的.易读的.低学习曲线的客户端请求代理模块,使用在NodeJS环境中.官方文档:http://visionmedia.github.io/superagent 简 ...
- springboot带分页的条件查询
QueryDSL简介 QueryDSL仅仅是一个通用的查询框架,专注于通过Java API构建类型安全的SQL查询. Querydsl可以通过一组通用的查询API为用户构建出适合不同类型ORM框架或者 ...
- Hadoop初体验(续)--YARN
1.Hadoop已经安装完成并启动成功 复制mapred-site.xml.template重命名为mapred-site.xml /etc/hadoop/mapred-site.xml.templa ...
- 扩展 Yii2 自带的日志组件
<?php /** * author : forecho <caizhenghai@gmail.com> * createTime : 2015/12/22 18:13 * desc ...
- 装箱问题【STL】
7-9 装箱问题(20 分) 假设有N项物品,大小分别为s1.s2.-.si.-.sN,其中si为满足1≤si≤100的整数.要把这些物品装入到容量为100的一批箱 ...
- 如何拯救一台glibc被干掉的Linux服务器
原文: 如何拯救一台glibc被干掉的Linux服务器? 首先如果 libc.so.6 没有被删除, 直接使用LD_PRELOAD就可以恢复 LD_PRELOAD=/lib64/libc-2.12.s ...