洛谷—— P2895 [USACO08FEB]流星雨Meteor Shower
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 搜索bfs,先预处理出每一个炸弹爆炸时对其每一个格子造成的影响,然后去一个最小值,然后bfs搜到第一个永远不会被炸的地方,输出答案,如果没有这样的地方,直接输出-1
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 500
#define maxn 0x3f3f3f3f
using namespace std;
bool flag;
int n,x,y,t,fx,fy,dis[N][N],map[N][N];
]={,,,-},yy[]={,-,,};
int read()
{
,f=; char ch=getchar();
; ch=getchar();}
+ch-'; ch=getchar();}
return x*f;
}
struct Node
{
int x,y;
}que;
int main()
{
n=read();
memset(map,maxn,sizeof(map));
;i<=n;i++)
{
x=read(),y=read(),t=read();
map[x][y]=min(map[x][y],t);
;i<;i++)
{
fx=x+xx[i],fy=y+yy[i];
||fy<) continue;
map[fx][fy]=min(map[fx][fy],t);
}
}
queue<Node>q;
que.x=,que.y=;
memset(dis,maxn,sizeof(dis));
q.push(que);dis[][]=;
while(!q.empty())
{
Node p=q.front();q.pop();
;}
;i<;i++)
{
int nx=p.x+xx[i],ny=p.y+yy[i];
||ny<||map[nx][ny]<=dis[p.x][p.y]+) continue;
) continue;
dis[nx][ny]=dis[p.x][p.y]+;
que.x=nx,que.y=ny;
q.push(que);
}
flag=true;
}
if(flag) printf("-1");
;
}
洛谷—— P2895 [USACO08FEB]流星雨Meteor Shower的更多相关文章
- 洛谷P2895 [USACO08FEB]流星雨Meteor Shower
题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...
- 洛谷 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 ...
随机推荐
- PHP将html内容转换为image图片
/** * 将html内容转换为image图片 * @param $htmlcontent * @param $toimagepath * @author james.ou 2011-11-1 */ ...
- 【mysql】【转发】my.cnf 讲解
PS:本配置文件针对Dell R710,双至强E5620.16G内存的硬件配置.CentOS 5.6 64位系统,MySQL 5.5.x 稳定版.适用于日IP 50-100w,PV 100-300w的 ...
- 有关fcrackzip的使用介绍(来自网络)
本文转自:http://longxiaz.blog.163.com/blog/static/131452420201282844545197/ 主要用到的工具是fcrackzip.别的工具没去测试,f ...
- Python爬虫,爬取实验楼全部课程
目的: 使用requests库以及xpath解析进行实验楼所有课程,存入MySQL数据 库中. 准备工作: 首先安装,requests库,lxml库,以及peewee库.在命令行模式,使用以下命令. ...
- Selenium WebDriver- 操作JavaScript的confirm弹窗
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- Andorid 生成NDK动态链接库 .so库
.so库第一次见到是在搜索Android保存静态秘钥等特殊id字段做法时看到的-通过NDK的方式将静态秘钥保存在so文件中, 关于原生开发工具包(NDK)详细见官网指南要更详细,这里我记录我度娘各种结 ...
- python之路 --- python模块初认识&数据类型
一.模块初识 首先,文件名不能和导入的模块名称一样.因为系统默认先从当前文件寻找模块名,如果文件名和导入的模块名称一样的话,就相当于自己调用自己,会找不到相应的方法的. sys模块 sys.path ...
- 移动端click时间、touch事件、tap事件详解
一.click 和 tap 比较 两者都会在点击时触发,但是在手机WEB端,click会有 200~300 ms,所以请用tap代替click作为点击事件. singleTap和doubleTap 分 ...
- python随机数的产生
导入 random模块 >>> import random 1. random.random random.random()用于生成一个0到1的随机浮点数: 0 <= n ...
- Python字典类型、
字典类型: # msg_dic = {# 'apple': 10,# 'tesla': 100000,# 'mac': 3000,# 'lenovo': 30000,# ...