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. NetAnalyzer笔记 之 五 一些抓包技巧分享(不定期更新)

    [创建时间:2016-03-12 10:00:00] [更新时间:2016-05-21 10:00:00] NetAnalyzer下载地址 前一段时间应为工作关系,NetAnalyzer笔记系列已经很 ...

  2. javascript定时器:setTimeout与setInterval

    概述: setTimeout:在指定的延迟时间之后调用一个函数或者执行一个代码片段,只执行一次: setInterval:周期性地调用一个函数(function)或者执行一段代码,重复执行: 语法格式 ...

  3. 【转】10分钟了解设计模式(C#)

    10分钟了解设计模式(C#) 最近把<大话设计模式>重温了下(看完序才知道原来作者是也是博客园园友,这本书的最早博客版本在这里).体会最深的就是面向接口编程的重要性,如何在自己的项目中进行 ...

  4. 【百度之星2014~初赛(第二轮)解题报告】Chess

    声明 笔者近期意外的发现 笔者的个人站点http://tiankonguse.com/ 的非常多文章被其他站点转载.可是转载时未声明文章来源或參考自 http://tiankonguse.com/ 站 ...

  5. ORA-01652:无法通过128(在表空间TEMP中)扩展temp段

    在Oracle数据库中进行order by or group by.索引的创建和重创建.distinct操作.union & intersect & minus sort-merge ...

  6. WebApi2官网学习记录---Attribute Routing

    从WebApi 1迁移到WebAPI 2要改变配置代码如下: WebApi 1: protected void Application_Start() { // WARNING - Not compa ...

  7. 分页搜索查询sql

    select * from (select t.*,rownum no from " + table + " t where scbj=0)where (no>(" ...

  8. ios9API基础知识总结(二)

    UIAlertView(警告框) UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"标题" message:@&qu ...

  9. OpenGL ES 2.0 限定符

    限定符 说明 作用 attribute 一般用于各个顶点各不相同的量,如顶点位置.颜色等 属性限定符,修饰的变量用来接收渲染管线传递进顶点着色器的当前顶点的各种属性值. 只能用来修饰符点数标量,浮点数 ...

  10. Masonry + Ajax 实现无限刷新瀑布流

    效果就如我的个人站yooao.cc,把我实现的思路分享给大家. Masonry渲染页面如果有图片时需要imagesLoaded辅助,不然有可能会造成布局重叠. 一个大体的思路:前端取得最后一篇文章的i ...