Meteor Shower
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12816   Accepted: 3451

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个陨石将砸向第一象限和正坐标抽,每块陨石砸的时间分别为Ti,从0,0出发,如何走才能达到安全位置;
用一个T[][]数组记录每个点的最早爆炸时间,vis标记该点是否被砸,如果该点不可能被砸,那么为安全位置,否则向四个方向扩展,改点可走的条件为改点没有走过以及该点爆炸的时间大于当前时间,对于走过的点标记T[][]为0,那么改点在以后就不可能再走。 反正我的思路好麻烦,每次都要写个函数对所有陨石进行遍历判断是否为安全位置。
AC:
 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define INF 0x3f3f3f
#define eps 1e-8
#define MAXN (50000+1)
#define MAXM (100000)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
using namespace std;
struct Node{
int x, y, step;
};
bool judge(int x, int y){
return x >= && y >= ;
}
bool vis[][];
int Move[][] = {,, ,-, ,, -,};
int T[][];
int BFS(int x, int y)
{
if(!vis[x][y])
return ;
queue<Node> Q;
Node now, next;
now.x = x; now.y = y; now.step = ;
Q.push(now);
while(!Q.empty())
{
now = Q.front();
Q.pop();
if(!vis[now.x][now.y])
return now.step;
for(int k = ; k < ; k++)
{
next.x = now.x + Move[k][];
next.y = now.y + Move[k][];
next.step = now.step + ;
if(!judge(next.x, next.y)) continue;
if(vis[next.x][next.y])
{
if(T[next.x][next.y] != INF && next.step < T[next.x][next.y])
{
T[next.x][next.y] = ;
Q.push(next);
}
}
else
return next.step;
}
}
return -;
}
int main()
{
int n;
while(Ri(n) != EOF)
{
CLR(vis, false); CLR(T, INF);
for(int i = ; i < n; i++)
{
int x, y, t;
Ri(x); Ri(y); Ri(t);
T[x][y] = min(T[x][y], t);
vis[x][y] = true;
for(int k = ; k < ; k++)
{
int xx = x + Move[k][];
int yy = y + Move[k][];
if(!judge(xx, yy)) continue;
vis[xx][yy] = true;
T[xx][yy] = min(T[xx][yy], t);
}
}
Pi(BFS(, ));
}
return ;
}

WA:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int vis[][],b[][];
struct node {int x,y,t;}m[];
bool cmp(node a,node b) {return a.t<=b.t;}
int n,Mint;
int dx[]={,,,,-},dy[]={,,-,,};
bool safe(node p)
{
int l=-,r=n,mid;
while(r-l>)
{
mid=(l+r)/;
if(m[mid].t>=p.t)
r=mid;
else
l=mid;
}
for(int i=r;i<n;i++)
{
for(int j=;j<;j++)
{
if(p.x==(m[i].x+dx[j])&&p.y==(m[i].y+dy[j]))
return ;
}
}
return ;
}
int bfs()
{
int i,j;
Mint=-;
queue<node> s;
node temp,next;
temp.x=temp.y=temp.t=;
s.push(temp);
while(!s.empty())
{
temp=s.front();
s.pop();
if(safe(temp))
{
Mint=temp.t;
break;
}
temp.t++;
int l=-,r=n,mid;
while(r-l>)
{
mid=(l+r)/;
if(m[mid].t>=temp.t)
r=mid;
else
l=mid;
}
while(m[r].t==temp.t)
{ for(int i=;i<=;i++)
b[m[r].x+dx[i]][m[r].y+dy[i]]=;
r++;
}
for(i=;i<=;i++)
{
next.x=temp.x+dx[i];
next.y=temp.y+dy[i];
next.t=temp.t;
if(next.x>=&&next.y>=&&vis[next.x][next.y]==&&b[next.x][next.y]==)
{
vis[next.x][next.y]=;
s.push(next);
}
//cout<<"ads";
}
}
return Mint;
}
int main()
{
int i,j;
freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
memset(vis,,sizeof(vis));
memset(b,,sizeof(vis));
for(i=;i<n;i++)
scanf("%d%d%d",&m[i].x,&m[i].y,&m[i].t);
sort(m,m+n,cmp);
//for(i=0;i<n;i++)
// cout<<m[i].x<<" "<<m[i y<<" "<<m[i].t<<endl;
i=;
bool flag=;
while(m[i].t==)
{
if((m[i].x==&&m[i].y==)||(m[i].x==&&m[i].y==)||(m[i].x==&&m[i].y==))
{
cout<<-<<endl;
flag=;
break;
}
i++;
}
if(flag)
continue;
bfs();
printf("%d\n",Mint);
}
}

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

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

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

  2. poj3669 Meteor Shower(预处理+bfs)

    https://vjudge.net/problem/POJ-3669 先给地图a[][]预处理每个位置被砸的最小时间.然后再bfs. 纯bfs,还被cin卡了下时间.. #include<io ...

  3. POJ 3669 Meteor Shower(流星雨)

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

  4. poj 3669 Meteor Shower(bfs)

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

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

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

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

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

  7. 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)

    Charm Bracelet    POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...

  8. Scout YYF I(POJ 3744)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5565   Accepted: 1553 Descr ...

  9. 广大暑假训练1(poj 2488) A Knight's Journey 解题报告

    题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A   (A - Children of the Candy Corn) ht ...

随机推荐

  1. SALT-API兼HALITE测试搞定

    妈XX,真的搞了近一周的空闲时间. 最后才领悟. 其实,先按HALITE的套路弄好,然后直接SALT-API就OK了..因为HALITE就是SALT-API的封闭和替代嘛. 随便参考一个URL搞定HA ...

  2. PowerShell 中的目录文件管理

    前面的一篇文章我们说了部分在PS中进行文件浏览的基本概念,说到了几个虚拟驱动器的概念.并没有深入的描述相关的命令,这里我们进一步对这一知识点进行描述. 2.1 管理当前工作路径/位置 在日常管理中经常 ...

  3. pl/sql执行动态sql

    SQL> declare             msql varchar2(200);    begin    loop    msql := 'select * from bfw_test' ...

  4. 【转】一个从32位机器移植到64位机器时的c问题

    原文网址:http://www.jiancool.com/article/96402954887/ 最近工作中遇到了一个讨厌的问题,在32位机器上运行的好好的,但是在64位机器上,出现了诡异的 Seg ...

  5. jsp中全局变量和局部变量的设置

  6. UVA12186--树型DP

    树型DP第一题...就是从boss到底层员工是一个树型结构,底层员工想加薪,如果每个boss都有超过T%的员工要求加薪,他就会往更高的bOSs传达,问如果让根节点的大boss接到加薪要求,最少要有多少 ...

  7. Android 之 Eclipse 导入 Android 源码

    很多人都下载过下图中的 Sources for Android SDK,但是很少人知道怎么用       下载完毕后可以再 Android SDK 根目录下看到 sources 文件夹内 有 andr ...

  8. 自定义一个searchBar

    #import "CZSearchBar.h" @implementation CZSearchBar - (instancetype)initWithFrame:(CGRect) ...

  9. AngularJs登录

    AngularJs 登录的简单实现 多数AngularJs应用离不开登录操作,最近阅读了一篇关于AngularJs登录的博客,博客中实现的登录系统demo能够应用于多数小型AngularJs应用,实现 ...

  10. mvc初学controller参数传递感想

    从视图中传递参数给controller也有很多种方式 方法一(推荐):路由 config.Routes.MapHttpRoute( name: "DefaultApi", rout ...