P2895 [USACO08FEB]流星雨Meteor Shower
预处理出每个位置最早被摧毁的时间,在此之前都可以走
直接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的更多相关文章
- bzoj1611 / P2895 [USACO08FEB]流星雨Meteor Shower
P2895 [USACO08FEB]流星雨Meteor Shower 给每个点标记一下能够走的最迟时间,蓝后bfs处理一下 #include<iostream> #include<c ...
- 洛谷—— 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则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽,届时将会对它撞到的一 ...
- ACM Meteor Shower
贝茜听到一场非同寻常的流星雨( meteor shower)即将来临;有报道称这些流星将撞击地球并摧毁它们所击中的任何东西.为了安全起见(Anxious for her safety), ,她发誓(v ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 904 Solved: 393 ...
- BZOJ 1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个 ...
随机推荐
- Reporting services
“数据库引擎服务”可以承载报表服务器数据库.Reporting Services 需要SQL Server 2008 数据库引擎的本地或远程实例来承载报表服务器数据库.如果同时安装数据库引擎实例和 R ...
- HotSpot JVM垃圾收集器
HotSpot JVM收集器 上面有7中收集器,分为两块,上面为新生代收集器,下面是老年代收集器.如果两个收集器之间存在连线,就说明它们可以搭配使用. Serial(串行GC)收集器 Serial收集 ...
- c#基础;初步学习循环语句
循环语句就是 在满足循环条件的情况下会有顺序的执行循环体 循环语句:for : while : foreach:三种. 循环语句 必须具备四要素:初始条件.循环条件.循环体.状 ...
- Opencv Laplacian(拉普拉斯算子)
#include <iostream>#include <opencv2/opencv.hpp>#include <math.h> using namespace ...
- session跨域共享
www.maxomnis.com的index.php文件内容 <?phpsession_start();setcookie("user", "alex proter ...
- 3、PACBIO下机数据如何看
转载:http://www.cnblogs.com/jinhh/p/8328818.html 三代测序的下机数据都有哪些,以及他们具体的格式是怎么样的(以sequel 平台为主). 测序过程 SMRT ...
- NCBI下载SRA数据
从NCBI下载数据本来是一件很简单的事情,但是今天碰到几个坑: 1.paper里没有提供SRA数据号.也没有提供路径: 2.不知道文件在ftp的地址,不能直接用wget下载 所以通过在NCBI官网,直 ...
- 判断wifi连接是否可用
/*** 判断当前连接方式是否是WIFI连接* * @param context* @return*/private static boolean isWifiConnected(Context co ...
- Dapper相关了解
公司新项目用的是Dapper,做的时候没有具体看dapper的具体用法,现在回来回顾总结一下. 1-总体介绍dapper 我们都知道ORM全称叫做Object Relationship Mapper, ...
- JavaScript知识体系索引
JavaScript 参考手册 www.w3school.com.cn JavaScript基础语法 JavaScript的数据类型 Javascript的对象分类 JavaScript内置对象 Ja ...