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年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个 ...
随机推荐
- C++11新特性之九——function、bind以及lamda表达式总结
本文是C++0x系列的第四篇,主要是内容是C++0x中新增的lambda表达式, function对象和bind机制.之所以把这三块放在一起讲,是因为这三块之间有着非常密切的关系,通过对比学习,加深对 ...
- js禁止img拖动
其实只需要一句代码即可,那就是阻止元素的默认事件: <body> <img src="./../imgs/cat.jpg" id="test" ...
- canvas二:绘制圆和其他曲线
1.绘制圆 绘制圆是canvas里面不可缺少的功课,而且绘制圆在canvas中的用处很多,好嘞,开扯 绘制圆需要用到arc这个方法: arc(X坐标,Y坐标,半径,起始弧度,结束弧度,旋转方向): 弧 ...
- webstorm编译less和scss
Webstorm 配置less编译的Arguments参数: $FileName$ $FileParentDir$\ccy\ccy1\ccy2\$FileNameWithoutExtension$.c ...
- C++ primer(十三)--类继承、构造函数成员初始化、虚函数、抽象基类
一.基类 从一个类派生出另一个类时,原始类称为基类,继承类称为派生类. 派生类对自身基类的private成员没有访问权限,对基类对象的protected成员没有访问权限,对派生类对象的(基类之 ...
- Deploying Cloud Foundry on OpenStack Juno and XenServer (Part II)
link http://rabbitstack.github.io/deploying-cloud-foundry-on-openstack-juno-and-xenserver-part-ii/ L ...
- Sencha中Element的使用
在sencha touch中如果你要是用模板来构造一些UI,那么你就必定要去操作Element,如下是我对Element的一些操作和遇到的问题 获取Elenent Ext.get("ID&q ...
- scss的安装使用
Ruby的安装 如果是Window系统,请打开:http://rubyinstaller.org/downloads/ ,下载当前稳定版本的exe文件.界面如下所示: Step(2): 接下来,在系统 ...
- 【BZOJ1054】[HAOI2008]移动玩具 BFS
[BZOJ1054][HAOI2008]移动玩具 Description 在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动 时只能将玩具向上下左右四个 ...
- 【BZOJ1630/2023】[Usaco2007 Demo]Ant Counting DP
[BZOJ1630/2023][Usaco2007 Demo]Ant Counting 题意:T中蚂蚁,一共A只,同种蚂蚁认为是相同的,有一群蚂蚁要出行,个数不少于S,不大于B,求总方案数 题解:DP ...