P2895 [USACO08FEB]流星雨Meteor Shower

给每个点标记一下能够走的最迟时间,蓝后bfs处理一下

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<queue>
#define re register
using namespace std;
void read(int &x){
char c=getchar();x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=(x<<)+(x<<)+(c^),c=getchar();
}
int min(int a,int b){return a<b?a:b;}
#define N 310
const int d1[]={,,-,,};
const int d2[]={,,,-,};
struct node{int x,y,t;}a;
queue <node> h;
int m,tp=,ans,dan[N][N],win; bool vis[N][N];
int main(){
memset(dan,,sizeof(dan)); int inf=dan[][];
read(m);
for(re int i=;i<=m;++i){
read(a.x);read(a.y);read(a.t);
++a.x; ++a.y;
dan[a.x][a.y]=min(dan[a.x][a.y],a.t);
dan[a.x][a.y+]=min(dan[a.x][a.y+],a.t);
dan[a.x][a.y-]=min(dan[a.x][a.y-],a.t);
dan[a.x+][a.y]=min(dan[a.x+][a.y],a.t);
dan[a.x-][a.y]=min(dan[a.x-][a.y],a.t);
}//处理每个点能走的最迟时间
h.push((node){,,}); vis[][]=;
if(dan[][]==inf) win=,ans=;
while(!h.empty()&&!win){
node u=h.front(); h.pop();
for(re int i=;i<&&!win;++i){
int r1=u.x+d1[i],r2=u.y+d2[i];
if(r1<||r2<||r1>=N||r2>=N) continue;
if(vis[r1][r2]||dan[r1][r2]<=u.t+) continue;
if(dan[r1][r2]==inf) win=,ans=u.t+;
else h.push((node){r1,r2,u.t+}),vis[r1][r2]=;
}
}win ? printf("%d",ans):printf("-1");
return ;
}

bzoj1611 / P2895 [USACO08FEB]流星雨Meteor Shower的更多相关文章

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

    P2895 [USACO08FEB]流星雨Meteor Shower 题目描述 Bessie hears that an extraordinary meteor shower is coming; ...

  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

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

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

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

  5. P2895 [USACO08FEB]流星雨Meteor Shower

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

  6. ACM Meteor Shower

    贝茜听到一场非同寻常的流星雨( meteor shower)即将来临;有报道称这些流星将撞击地球并摧毁它们所击中的任何东西.为了安全起见(Anxious for her safety), ,她发誓(v ...

  7. BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨

    1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 904  Solved: 393 ...

  8. POJ 3669 Meteor Shower(流星雨)

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

  9. BZOJ 1611: [Usaco2008 Feb]Meteor Shower流星雨

    1611: [Usaco2008 Feb]Meteor Shower流星雨 Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个 ...

随机推荐

  1. cocos2d-x游戏引擎核心之八——多线程

    一.多线程原理 (1)单线程的尴尬 重新回顾下 Cocos2d-x 的并行机制.引擎内部实现了一个庞大的主循环,在每帧之间更新各个精灵的状态.执行动作.调用定时函数等,这些操作之间可以保证严格独立,互 ...

  2. 《C++ Primer Plus》第7章 函数——C++的编程模块 学习笔记

    函数是C++的编程模块.要使用函数,必须提供定义和原型,并调用该函数.函数定义是实现函数功能的代码:函数原型描述了函数的接口:传递给函数的值的书目和种类以及函数的返回类型.函数调用使得程序将参数传递给 ...

  3. PyQt4发射信号

    继承自QtCore.QObject的对象均可以发射信号.如果我们单击一个按钮,那么一个clicked()信号就会被触发.下面的示例演示如何手动发射一个信号. #!/usr/bin/python # - ...

  4. 【PHP】 php实现字符串反转:支持中英文

    strrev  函数对英文很好用,直接可以实现字符串翻转 但是面对中文呢?肯定都是乱码,对于这样的问题有很多,比如strstr,substr等函数都是这样的. PHP提供了mb_类的函数实现不同编码. ...

  5. LeetCode——House Robber

    Description: You are a professional robber planning to rob houses along a street. Each house has a c ...

  6. [MongoDB]安装MongoDB遇到问题

    1. 首先,当然是下载 MongoDB MongoDB的官方网站是:http://www.mongodb.org/, 最新版本下载在:http://www.mongodb.org/downloads  ...

  7. This function has none of DETERMINISTIC, NO SQL

    错误信息: [Err] 1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declara ...

  8. HDCMS留言插件的使用!

    HDCMS留言插件,JS简单示例: <img src='{|U:'code'}' onclick='this.src='{|U:'code'}&'+Math.random()' /> ...

  9. Spring----学习参考博客书单链接

    [References] 1.IOC之基于Java类的配置Bean 2.IOC之基于注解的配置bean(上) 3.Spring之IOC的注入方式总结 4.Spring之IOC自动装配解析 5.Spri ...

  10. Python 使用 Matplotlib 做图时,如何画竖直和水平的分割线或者点画线或者直线?

    作者:看看链接:https://www.zhihu.com/question/21929761/answer/164975814 可以使用: vlines(x, ymin, ymax) hlines( ...