Meteor Shower
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21055   Accepted: 5499

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 (1 ≤ M ≤ 50,000) will strike, with meteor i will striking point (XiYi) (0 ≤ X≤ 300; 0 ≤ Y≤ 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.

Input

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

Output

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

Sample Input

4
0 0 2
2 1 2
1 1 2
0 3 5

Sample Output

5

题意:

输入m组数,每组分别代表x,y坐标和陨石落在改点时的时间t。从零点出发,问是否有生还的可能。

设mp数组初始值为-1,然后存入时间t。

用bfs层次遍历直到找出mp==-1的点,返回现在的t。

AC代码:

 //#include<bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <list>
#include <sstream>
#include <set>
#include <functional>
using namespace std; const int MAX=; struct node{
int x;int y;int t;
}s,temp; int m;
int mp[MAX][MAX];
int dir[][]={{,},{,},{,},{-,},{,-}};
queue<node> q; int bfs(){
if(mp[][]==-) return ;
if(mp[][]==) return -;
s.x=;
s.y=;
s.t=;
q.push(s);
while(!q.empty()){
temp=q.front();
q.pop();
for(int i=;i<;i++){
s.x=temp.x+dir[i][];
s.y=temp.y+dir[i][];
s.t=temp.t+;
if(s.x<||s.x>=MAX||s.y<||s.y>=MAX) continue;
if(mp[s.x][s.y]==-) return s.t;
if(mp[s.x][s.y]<=s.t) continue;
mp[s.x][s.y]=s.t;
q.push(s);
}
}
return -;
} int main(){
ios::sync_with_stdio(false);
cin>>m;
memset(mp,-,sizeof(mp));
while(m--){
int x,y,t;
cin>>x>>y>>t;
for(int i=;i<;i++){
int nx=x+dir[i][];
int ny=y+dir[i][];
if(nx<||nx>=MAX||ny<||ny>=MAX)
continue;
if(mp[nx][ny]==-)
mp[nx][ny]=t;
else
mp[nx][ny]=min(mp[nx][ny],t);
}
}
cout<<bfs()<<endl;
return ;
}

POJ-3669的更多相关文章

  1. POJ 3669 Meteor Shower【BFS】

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

  2. POJ 3669 Meteor Shower(流星雨)

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

  3. 广搜最短路(最短时间到达目的地),POJ(3669)

    题目链接:http://poj.org/problem?id=3669 解题报告: 1.流星坠落的点,四周和自己本身都被毁灭,不断更新每个点被毁灭的时候的最短时间. 2.搜索终点是,到达某个点,这个不 ...

  4. POJ 3669 Meteor Shower BFS 水~

    http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...

  5. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  6. poj 3669 线段树成段更新+区间合并

    添加 lsum[ ] , rsum[ ] , msum[ ] 来记录从左到右的区间,从右到左的区间和最大的区间: #include<stdio.h> #define lson l,m,rt ...

  7. BFS:Meteor Shower(POJ 3669)

         奔跑吧,傻牛 题目大意:这只Bessie的牛又要来闹事了,这次她的任务就是来躲流星雨,流星雨就是在一定时间会从天上砸到Bessie的所在的正方形区域内(Bessie在0,0的位置),然后砸下 ...

  8. poj 3669 Meteor Shower

                                                                                                      Me ...

  9. POJ 3669 广度优先搜索

    题意:巨大流星雨即将袭来.每个流星会对击中的地方以及周围(上下左右四格)造成破坏.Bessie开始时位于(0, 0)位置,并希望逃到一处不会被袭击到的地方(在第一象限内).已知每移动一格需要1个时间单 ...

  10. poj 3669 Meteor Shower(bfs)

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

随机推荐

  1. python爬虫入门篇

    优质爬虫入门源码:https://github.com/lining0806/PythonSpiderNotes Python Spider:https://www.cnblogs.com/wangy ...

  2. ch.poweredge.ntlmv2-auth

    <dependency> <groupId>ch.poweredge.ntlmv2-auth</groupId> <artifactId>ntlmv2- ...

  3. tps 与 事务平均响应时间关系对答(转)

    问者:每秒处理的事务数和事务的平均响应时间 怎么个关系,有关系吗 kaku21:举个例子:一个高速路 有10个入口,每个入口每秒钟只能进1辆车,请问1秒钟最多能进几辆车?? 问者:10 kaku21: ...

  4. 【BZOJ3696】化合物 树形DP+暴力

    [BZOJ3696]化合物 Description 首长NOI惨跪,于是去念文化课了.现在,他面对一道化学题.    这题的来源是因为在一个奇怪的学校两个化竞党在玩一个奇怪的博弈论游戏.这个游戏很蛋疼 ...

  5. Something Starts While Something Ends

    (1)最终还是没能参加比赛,一次都没有机会. (2)有梦想,不到最后一刻不会放弃. (3)这里应该会搬次家,转到github上. (4)作为一个新手,什么东西都需要从头学起来,就从最基础的数据结构开始 ...

  6. WePY根据环境变量来改变运行时的参数

    WePY根据环境变量来改变运行时的参数 · Tencent/wepy Wiki https://github.com/Tencent/wepy/wiki/WePY%E6%A0%B9%E6%8D%AE% ...

  7. Brotli

    https://engineering.linkedin.com/blog/2017/05/boosting-site-speed-using-brotli-compression?utm_sourc ...

  8. http://blog.csdn.net/wh211212/article/details/53005321

    http://blog.csdn.net/wh211212/article/details/53005321

  9. cygwin添加到有右键菜单

    cygwin添加到有右键菜单 前提 为了在windows中使用cygwin编译指定文件代码更为方便,所以动心思琢磨把cygwin添加到右键菜单,百度了一下,发现很多这样的教程,但是有问题,比如添加了但 ...

  10. 【转】如何让虚拟目录里面的webconfig不继承网站的设置

    [转]http://www.cnblogs.com/Sue_/articles/2037556.html 必須在上一层虚拟目录(如根目录)所在的Web.config加上 如:<location ...