传送门

预处理出每个位置最早被摧毁的时间,在此之前都可以走

直接dfs加个记忆化和最优性剪枝就好了

一定要注意流星的边界,如果波及到负数坐标的位置不要去考虑会RE

一定要考虑流星砸到边界的情况 如 (300,300) 那么(300,301) 和 (301,300) 的位置都会被波及不安全,也要考虑到

注意奶牛可以跑出边界!比如(301,300)

代码简单,就不注释了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=,xx[]={,,,-},yy[]={,,-,};
int n,ans=1e9;
int mp[N][N],f[N][N];
void dfs(int x,int y,int stp)
{
if(stp>=ans||(mp[x][y]!=-&&stp>=mp[x][y])) return;
if(f[x][y]&&f[x][y]<=stp) return;
f[x][y]=stp; if(mp[x][y]==-) { ans=stp; return; }
for(int k=;k<;k++)
{
if(x+xx[k]<||y+yy[k]<) continue;
dfs(x+xx[k],y+yy[k],stp+);
}
}
int main()
{
memset(mp,-,sizeof(mp));
int a,b,c;
n=read();
for(int i=;i<=n;i++)
{
a=read(); b=read(); c=read();
if(mp[a][b]>c||mp[a][b]==-) mp[a][b]=c;
for(int k=;k<;k++)
{
int x=a+xx[k],y=b+yy[k];
if(x<||y<) continue;
if(mp[x][y]>c||mp[x][y]==-) mp[x][y]=c;
}
}
dfs(,,);
printf("%d",ans==1e9 ? - : ans);
return ;
}

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

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

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

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

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

  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

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

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

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

  6. ACM Meteor Shower

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

  7. POJ 3669 Meteor Shower(流星雨)

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

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

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

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

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

随机推荐

  1. C#高级参数out的使用

    C#中有三个高级参数,分别是out,ref,params.本文章中先来介绍out参数的使用. out,用于在方法中返回多余值.(可以理解为让一个方法返回不同的类型值) 我们通过例子来理解例子的功能:用 ...

  2. MySQL 删除字段数据某关键字后的所有数据

    ),'开发商') WHERE Compay LIKE '%开发商%'; sql附上

  3. 使用R语言绘制图表

    #========================================================#wolf moose graph version 20170616.R###Data ...

  4. eclips git中的add to Index无效解决

    今天在使用eclips git中的add to Index,发现其无效,具体如下 问题描述: 通过export导入一个git java项目 在java工程中新增一个类文件IndicatorCalcTe ...

  5. C++ 成员函数前和函数后加const修饰符区别

    博客转载自: https://www.iteblog.com/archives/214.html 分析以下一段程序,阐述成员函数后缀const 和 成员函数前const 的作用 #include< ...

  6. java内存模型和线程安全

  7. 《Head First Servlets & JSP》-8-无脚本的JSP

    以前servlet和JSP交互的代码 servlet代码示例: JSP代码示例: 若属性不是一个String而是一个Bean呢? 一个简单的JavaBean servlet代码示例: JSP代码示例: ...

  8. 找BUG

    找一找BUG 一段代码,实现一个pop,push,和getmin都是O(1)的方法. 最初源代码 伙伴代码如下,代码的地址可以通过这个访问: Ubuntu Pastebin https://paste ...

  9. maven tomcat:run指定tomcat7:

    配置好下面的内容后,执行 run as -> tomcat7:run 或者tomcat6:run可以将maven的web应用在tomcat6/7里面运行 ,eclipse Indigo 版本默认 ...

  10. 怎么自动响应richTextBox超级链接单击click事件

    如上图所示,怎么自动响应richTextBox超级链接单击click事件?步骤如下: 1. 增加 richTextBox1_LinkClicked 事件: 2.  编辑事件内容如下: private ...