bzoj1611 / P2895 [USACO08FEB]流星雨Meteor Shower
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的更多相关文章
- 洛谷—— P2895 [USACO08FEB]流星雨Meteor Shower
P2895 [USACO08FEB]流星雨Meteor Shower 题目描述 Bessie hears that an extraordinary meteor shower is coming; ...
- 洛谷P2895 [USACO08FEB]流星雨Meteor Shower
题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...
- 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower
题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...
- 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower 解题报告
一起来看流星雨吧(话说我还没看到过流星雨呢) 题目 Problem 小A则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽,届时将会对它撞到的一 ...
- P2895 [USACO08FEB]流星雨Meteor Shower
传送门 预处理出每个位置最早被摧毁的时间,在此之前都可以走 直接dfs加个记忆化和最优性剪枝就好了 一定要注意流星的边界,如果波及到负数坐标的位置不要去考虑会RE 一定要考虑流星砸到边界的情况 如 ( ...
- ACM Meteor Shower
贝茜听到一场非同寻常的流星雨( meteor shower)即将来临;有报道称这些流星将撞击地球并摧毁它们所击中的任何东西.为了安全起见(Anxious for her safety), ,她发誓(v ...
- BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 904 Solved: 393 ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- BZOJ 1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个 ...
随机推荐
- 使用Node.js完成路由
首先先看一下文件的结构: 我想通过改变不同的路由进不同的页面, 先看这几个HTML页面: 404: <!DOCTYPE html> <html lang="en" ...
- .net 防盗链
Global.asax 文件中 protected void Application_BeginRequest(object sender, EventArgs e) { //判断当前请求是否是访问 ...
- 《转》python学习--基础上
学习的python本来想自己总结,但是发现了一篇不错的大牛的博客,拿来主义,,又被我实践了 关于前两篇如果总结的不详细,因此把他人的转载过来 http://www.cnblogs.com/BeginM ...
- Codeforces Round #375 (Div. 2)E. One-Way Reform
题目链接:传送门 题目大意:一副无向图,要求你给边定向(变为有向图),使出度等于入度的点最多,输出有多少 个点,并且输出定向后的边(前为起点,后为终点) 题目思路:欧拉路 我们这样考虑,先考虑无向图的 ...
- PHP获取POST的原始数据的方法
一般我们都用$_POST或$_REQUEST两个预定义变量来接收POST提交的数据.但如果提交的数据没有变量名,而是直接的字符串,则需要使用其他的方式来接收. 方法一: 使用全局变量$GLOBALS[ ...
- ScrollView 设置滚动是否可用
extends:http://stackoverflow.com/questions/5763304/disable-scrollview-programmatically , http://stac ...
- Unity3D笔记十二 游戏元素二之摄像机
一.摄像机 摄像头用以捕捉和显示的世界给玩家.通过自定义和操纵相机,你可以让你的游戏的呈现真正独一无二的.您可以在一个场景无限数量的摄像机.它们可以设置在任何顺序呈现在屏幕上的任何地方,或者屏幕的某些 ...
- ExcelUtil工具类
import com.google.common.base.Strings;import com.jianwu.util.excel.annotation.ExcelAttribute;import ...
- hdu4975 网络流解方程组(网络流+dfs判环或矩阵DP)
http://acm.hdu.edu.cn/showproblem.php?pid=4975 A simple Gaussian elimination problem. Time Limit: 20 ...
- Visual Studio实用小技巧
有一个有关微软Office的笑话,说的是它的特性太多: 当你觉得自己发现了一个Office的新特性时,它已经存在很多年了. 本文将介绍一些在Visual Studio(免费下载)中很实用却被忽略的小技 ...