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.

输入输出样例

输入样例#1:

4
0 0 2
2 1 2
1 1 2
0 3 5
输出样例#1:

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的更多相关文章

  1. 洛谷P2895 [USACO08FEB]流星雨Meteor Shower

    题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...

  2. 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower

    题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...

  3. 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower 解题报告

    一起来看流星雨吧(话说我还没看到过流星雨呢) 题目 Problem 小A则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽,届时将会对它撞到的一 ...

  4. bzoj1611 / P2895 [USACO08FEB]流星雨Meteor Shower

    P2895 [USACO08FEB]流星雨Meteor Shower 给每个点标记一下能够走的最迟时间,蓝后bfs处理一下 #include<iostream> #include<c ...

  5. P2895 [USACO08FEB]流星雨Meteor Shower

    传送门 预处理出每个位置最早被摧毁的时间,在此之前都可以走 直接dfs加个记忆化和最优性剪枝就好了 一定要注意流星的边界,如果波及到负数坐标的位置不要去考虑会RE 一定要考虑流星砸到边界的情况 如 ( ...

  6. 洛谷 P2895 [USACO08FEB]Meteor Shower S (BFS)

    题意:你刚开始位于坐标轴的\((0,0)\)点,一共有\(m\)颗流星砸向地面,每颗流星在\(t\)时砸到\((x,y)\)点,其四周上下左右也均有波及,你每秒可以向上下左右移动一个单位,问你是否可以 ...

  7. 洛谷P2894 [USACO08FEB]酒店Hotel

    P2894 [USACO08FEB]酒店Hotel https://www.luogu.org/problem/show?pid=2894 题目描述 The cows are journeying n ...

  8. 洛谷 P2894 [USACO08FEB]酒店Hotel-线段树区间合并(判断找位置,不需要维护端点)+分治

    P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultur ...

  9. 洛谷 P2894 [USACO08FEB]酒店Hotel 解题报告

    P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultur ...

随机推荐

  1. Mac远程访问Ubuntu

    MacOS和Ubuntu连接到同一个网络使用ping命令可以通信即可.SSH使用SSH可以很方便的在MacOS上访问Ubuntu,不过只能用命令行操作,相当于连接了Ubuntu的终端. 1. Ubun ...

  2. bin、hex、elf、axf文件的区别

    1.bin Bin文件是最纯粹的二进制机器代码, 或者说是"顺序格式".按照assembly code顺序翻译成binary machine code,内部没有地址标记.Bin是直 ...

  3. POJ:1086-Parencodings

    Parencodings Time Limit: 1000MS Memory Limit: 10000K Description Let S = s1 s2-s2n be a well-formed ...

  4. ACM-ICPC 2016 Qingdao Preliminary Contest G. Sort

    Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receives a task from A ...

  5. linux笔记(1)

    1)useradd+用户名 添加一个普通用户2)passwd+密码 为用户加密码3)su - 用户名 切换用户4)whoami 查看当前用户是什么5)$符号是普通用户#是超级用户6)mkdir /da ...

  6. mongodb v2.4.9 快速操作记录

    参考链接:http://www.runoob.com/mongodb/mongodb-tutorial.html oschina链接:https://gitee.com/dhclly/icedog.s ...

  7. 如何理解C4.5算法解决了ID3算法的偏向于选择取值较多的特征问题

    如何理解C4.5算法解决了ID3算法的偏向于选择取值较多的特征问题 考虑一个极端情况,某个属性(特征)的取值很多,以至于每一个取值对应的类别只有一个.这样根据\[H(D) - H(D|A)\]可以得知 ...

  8. ssh 远程执行绝对路径命令mysqld_multi 报my_print_defaults不存在

    通过SSH直接执行远程命令(这种方式会使用Bash的non-interactive + non-login shell模式)找不到命令参考:http://ghoulich.xninja.org/201 ...

  9. 【Luogu】P3389高斯消元模板(矩阵高斯消元)

    题目链接 高斯消元其实是个大模拟qwq 所以就着代码食用 首先我们读入 ;i<=n;++i) ;j<=n+;++j) scanf("%lf",&s[i][j]) ...

  10. Codeforces 899D Shovel Sale

    题目大意 给定正整数 $n$($2\le n\le 10^9$). 考虑无序整数对 $(x, y)$($1\le x,y\le n, x\ne y$). 求满足 「$x+y$ 结尾连续的 9 最多」的 ...