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年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个 ...
随机推荐
- VMware创建虚拟机教程详解及问题解决
关于VMware Workstation Pro虚拟机创建教程,本教程主要详细描述使用软件VMware Workstation Pro建虚拟系统过程中步骤详解,以及个人安装时所出现部分问题的解决方案. ...
- JS-对象查找父级
之前在寻找两个以上的父级,一直傻傻的用parent().parent()... 今天,需要写五个,当然以前也是写过五个的,但是今天总想着换个简单的方式,至少不要.parent().parent().p ...
- Android Activity与Fragment生命周期 对应关系
- python小项目练习之转换像素图片为字符图
实例来源实验楼网站,没事可以多逛逛,在此多谢实验楼的无私分享 from PIL import Image import argparse """ description: ...
- CRUX下实现进程隐藏(1)
想必能找到这里的都是被吴一民的操作系统大作业坑过的学弟学妹了,当初我也是千辛万苦才把这个作业完成了,本着服务后辈的宗旨,尽量让学弟学妹少走弯路,我会把实现的大概思路记录下来.本系列一共三篇文章,分别实 ...
- 微信小游戏5.2.2 没有xml支持库的问题解决
需要下载xml支持库,并在game.js添加 window.DOMParser = require("./xmldom/xmldom.js").DOMParser; 如下图:
- MariaDB快速选择最适合您的需要的存储引擎
1.Xtradb和InnoDB是一个很好的通用事物存储引擎.通常不确定选用何种存储引擎时,Xtradb和InnoDB是最佳的选择. 2.MyISAM和Aria,占用空间小,系统之间容易复制.MyISA ...
- 三维凸包求内部一点到表面的最近距离(HDU4266)
http://acm.hdu.edu.cn/showproblem.php?pid=4266 The Worm in the Apple Time Limit: 50000/20000 MS (Jav ...
- 编译安装基于nginx与lua的高性能web平台-openresty
1.首先编译安装nginx(不多说) 2.开始安装openresty cd /usr/local/src wget https://openresty.org/download/openresty-1 ...
- 朴素贝叶斯算法的python实现 -- 机器学习实战
import numpy as np import re #词表到向量的转换函数 def loadDataSet(): postingList = [['my', 'dog', 'has', 'fle ...