Description

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 ( ≤ M ≤ ,) will strike, with meteor i will striking point (Xi, Yi) ( ≤ Xi ≤ ;  ≤ Yi ≤ ) at time Ti ( ≤ Ti  ≤ ,). Each meteor destroys the point that it strikes and also the four rectilinearly adjacent lattice points.

Bessie leaves the origin at time  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 ) 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.

Input

* Line : A single integer: M
* Lines ..M+: Line i+ contains three space-separated integers: Xi, Yi, and Ti

Output

* Line : The minimum time it takes Bessie to get to a safe place or - if it is impossible.

Sample Input


Sample Output


Source

 
 
有个小文青去看流星雨,不料流星掉下来会砸毁上下左右中五个点。每个流星掉下的位置和时间都不同,求小文青能否活命,如果能活命,最短的逃跑时间是多少?
有个地方给写错了,wa了很久,太粗心了//code 72行
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<vector>
#include<map>
#include<queue>
using namespace std;
#define N 506
int mp[N][N];
int dirx[]={,,-,};
int diry[]={-,,,};
int vis[N][N];
struct Node{
int x,y,t;
};
int bfs(){
if(mp[][]==-) return ;
if(mp[][]==) return -;
Node s;
s.x=;
s.y=;
s.t=;
vis[][]=;
queue<Node>q;
q.push(s);
Node t1,t2;
while(!q.empty()){
t1=q.front();
q.pop();
for(int i=;i<;i++){
t2.x=t1.x+dirx[i];
t2.y=t1.y+diry[i];
t2.t=t1.t+;
if(t2.x< || t2.x>=N || t2.y< || t2.y>=N) continue;
if(mp[t2.x][t2.y]==-){
return t2.t;
}
if(t2.t>=mp[t2.x][t2.y]) continue;
if(vis[t2.x][t2.y]) continue;
vis[t2.x][t2.y]=;
//mp[t2.x][t2.y]=t2.t;
q.push(t2);
}
}
return -;
}
int main()
{
int m;
while(scanf("%d",&m)==){
memset(mp,-,sizeof(mp));
memset(vis,,sizeof(vis));
for(int i=;i<m;i++){
int x,y,t;
scanf("%d%d%d",&x,&y,&t);
if(mp[x][y]==-){//处理(x,y)这点
mp[x][y]=t;
}
else{
mp[x][y]=min(mp[x][y],t);
} for(int j=;j<;j++){//处理周围4个点
int xx=x+dirx[j];
int yy=y+diry[j];
if(xx< || xx>=N || yy< || yy>=N) continue;
if(mp[xx][yy]==-){
mp[xx][yy]=t;
}
else{
mp[xx][yy]=min(mp[xx][yy],t);
}
}
} printf("%d\n",bfs()); }
return ;
}

poj 3669 Meteor Shower(bfs)的更多相关文章

  1. 题解报告:poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  2. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  3. POJ 3669 Meteor Shower (BFS+预处理)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  4. poi 3669 meteor shower (bfs)

    题目链接:http://poj.org/problem?id=3669 很基础的一道bfs的题,然而,我却mle了好多次,并且第二天才发现错在了哪里_(:з)∠)_ 写bfs或者dfs一定要记得对走过 ...

  5. 【POJ - 3669】Meteor Shower(bfs)

    -->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...

  6. POJ 3669 Meteor Shower【BFS】

    POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...

  7. POJ 3369 Meteor Shower (BFS,水题)

    题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...

  8. POJ 3669 Meteor Shower BFS求最小时间

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31358   Accepted: 8064 De ...

  9. poj 3669 Meteor Shower

                                                                                                      Me ...

随机推荐

  1. MySQL精粹

    关于Mysql整理的需要记忆和熟练掌握的内容 1.查询数据表的信息(比如有多少行数据): show table status like 'tab_User' -- 数据表中的数量   2. 使用 ex ...

  2. python入门第一天,循环与判断

    学习一门新的语言最重要的就是练习. 一.脚本需求: 编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 二.脚本流程图: 写代码之前画个流程图总是好的,可以让你理清思路,避免写着写着 ...

  3. python标准库基础之mmap:内存映射文件

    #作用:建立内存映射文件而不是直接读取内容文本信息内容:如下(名称是text.txt) Lorem ipsum dolor sit amet, consectetuer adipiscing elit ...

  4. Linux RAR 安装和使用详细说明

    描述:Linux默认自带ZIP压缩,最大支持4GB压缩,RAR的压缩比大于4GB.  流程:下载 >安装 > 使用  ----------------------------------- ...

  5. 【InversionCount 逆序对数 + MergeSort】

    Definition of Inversion: Let (A[0], A[1] ... A[n], n <= 50) be a sequence of n numbers. If i < ...

  6. LoadRunner测试下载功能点脚本(方法一)

    性能需求:对系统某页面中,点击下载功能做并发测试,以获取在并发下载文件的情况下系统的性能指标. 备注:页面上点击下载时的文件可以是word.excel.pdf等. 问题1:录制完下载的场景后,发现脚本 ...

  7. Java清洁:终结处理和垃圾回收

    一般情况:Java有垃圾回收机制负责回收无用对象占据的内存资源. 特殊情况:假定你的对象(并非使用new)获得一块特殊的内存区域,由于垃圾回收器只知道释放那些经由new分配的内存,所以它不知道如何释放 ...

  8. Linux的用户和组

    1. 查看配置文件/etc/shadow第一行中root账号的第三个字段(以':'分隔)中的数字,请算一下这个数字是怎么来的?距离1970年1月1日到上次更改密码的时间的间隔天数.例如root密码日期 ...

  9. artDialog Error: document.compatMode === "BackCompat 报错原因

    今天在使用artDialog的时候报错了提示artDialog Error: document.compatMode === "BackCompat 查了网上说 可以设置<!DOCTY ...

  10. iOS8怎么降级到iOS7,苹果iOS8怎么刷回iOS7

    iOS8怎么降级到iOS7,苹果iOS8怎么刷回iOS7 http://jingyan.baidu.com/article/e75aca855c5c19142edac6e9.html 威锋APPLE工 ...