bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨【BFS】
t记录每个格子最早被砸的时间,bfs(x,y,t)表示当前状态为(x,y)格子,时间为t。因为bfs,所以先搜到的t一定小于后搜到的,所以一个格子搜一次就行
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int N=505,inf=1e9,dx[]={-1,1,0,0,0},dy[]={0,0,-1,1,0};
int n,m,t[N][N];
bool v[N][N];
struct qwe
{
int x,y,t;
qwe(int X=0,int Y=0,int T=0)
{
x=X,y=Y,t=T;
}
};
queue<qwe>q;
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
inline bool ok(int x,int y,int z)
{
return x>=0&&y>=0&&t[x][y]>z&&!v[x][y];
}
int main()
{
n=read();
for(int i=0;i<=500;i++)
for(int j=0;j<=500;j++)
t[i][j]=inf;
for(int i=1;i<=n;i++)
{
int x=read(),y=read(),z=read();
for(int j=0;j<5;j++)
if(x+dx[j]>=0&&y+dy[j]>=0)
t[x+dx[j]][y+dy[j]]=min(t[x+dx[j]][y+dy[j]],z);
}
q.push(qwe(0,0,0));
v[0][0]=1;
while(!q.empty())
{
int x=q.front().x,y=q.front().y,z=q.front().t;
q.pop();
if(t[x][y]==inf)
{
printf("%d\n",z);
return 0;
}
for(int i=0;i<4;i++)
if(ok(x+dx[i],y+dy[i],z+1))
{
v[x+dx[i]][y+dy[i]]=1;
q.push(qwe(x+dx[i],y+dy[i],z+1));
}
}
puts("-1");
return 0;
}
bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨【BFS】的更多相关文章
- BZOJ 1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个 ...
- BZOJ——1611: [Usaco2008 Feb]Meteor Shower流星雨
http://www.lydsy.com/JudgeOnline/problem.php?id=1611 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1 ...
- 1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1010 Solved: 44 ...
- 【BZOJ】1611: [Usaco2008 Feb]Meteor Shower流星雨(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1611 一眼题,bfs. #include <cstdio> #include <c ...
- [Usaco2008 Feb]Meteor Shower流星雨[BFS]
Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的 ...
- BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 904 Solved: 393 ...
- [Usaco2008 Feb]Meteor Shower流星雨
去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的一切东西造成毁灭性的打击 ...
- poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- POJ 3669 Meteor Shower (BFS+预处理)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
随机推荐
- java发送短信验证码的功能实现
总结一下发送短信验证码的功能实现 (题外话:LZ是在腾讯云买的第三方(山东鼎信)短信服务平台的接口,1块钱20次的套餐来练手,哈哈,给他们打个广告,有需要的可以去购买哈,下面是购买链接短信服务平台购买 ...
- requests模块发送POST请求
在HTTP协议中,post提交的数据必须放在消息主体中,但是协议中并没有规定必须使用什么编码方式,从而导致了 提交方式 的不同.服务端根据请求头中的 Content-Type 字段来获知请求中的消息主 ...
- restful(2):视图
视图部分小结: # as_view()中的参数:利用参数(一个字典)来指定什么方式用什么方法来执行(哪种请求方式由哪种内部方法来执行) # 例如 Retrieve时,需要在对应的url中添加有名分组 ...
- hdu - 1254 推箱子 (bfs+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1254 题目意思很简单,只要思路对就好. 首先考虑搬运工能否到达推箱子的那个点,这个可以根据箱子前进方向得出搬运工 ...
- Rooks-LightOj1005(规律)
A rook is a piece used in the game of chess which is played on a board of square grids. A rook can o ...
- Redis基于客户端分片的集群案例(待实践)
说明: 下面的示例基本都是基于Linux去实现,目的是为了环境的统一,以便于把性能调整到最优.且基于Java.建议生产环境不要使用Windows/Mac OS这些. 在Java领域,基于客户端进行分片 ...
- JSP处理XML数据
以下内容引用自http://wiki.jikexueyuan.com/project/jsp/xml-data.html: 当通过HTTP发送XML数据时,使用JSP处理传入和传出的XML文件是有意义 ...
- pymongo collection.save 问题
项目中有这样一个需求,把路由器信息存入mongo,DB的结构如下: { router_name: name, router_ip: ip, interfaces: [ {oid:1,name:if1} ...
- swift container server 莫名stuck
openstack swift container server的进程经常莫名其妙进入 D Ds等状态 记录一下这个时候 storage.error的log 便于分析 一种情形是下面这种log Jun ...
- Logstash学习系列之基础介绍
Logstash功能特性 能集中处理各种类型的数据 能标准化不同模式和格式的数据 能快速的扩展自定义日志的格式 它具有收集,分析和转发数据流的功能 Logstash运行参数 -f 指定配置文件 -e ...