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 ...
随机推荐
- Leetcode 187.重复的DNA序列
重复的DNA序列 所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮 ...
- Less Time, More profit 最大权闭合子图(最大流最小割)
The city planners plan to build N plants in the city which has M shops. Each shop needs products fro ...
- 04-js的运算符
<html> <head> <title>js的运算符学习</title> <meta charset="UTF-8"/> ...
- LENOVO System x3850 X6
http://appserver.lenovo.com.cn/Lenovo_Series_List.aspx?CategoryCode=A31B01
- MongoDB小结27 - 聚合管道【$project】
我们有这样的数据 { "_id" : 1, title: "abcdef", isbn: "6969696969", author: { l ...
- 在Windows下搭建RocketMQ
原文:http://blog.csdn.net/u014134180/article/details/51790988 目录 目录 一 准备工作 1 RocketMQ部署架构1 2 环境配置 二 安装 ...
- Redux 中文文档
http://cn.redux.js.org/docs/introduction/Ecosystem.html
- dubbo的jmeter压测时jar包的热加载/动态加载
在做dubbo的jmeter压测时,需要把jar包放入jmeter的lib/ext目录下,但是jmeter启动的时候会自动加载这个目录lib目录及lib/ext目录,这样启动后放入这些目录下的jar包 ...
- 【结果发布】第六届SeedCoder编程大赛初赛结果发布
微软俱乐部科技文化月seedcoder2014编程大赛已经初审完成. 评审小组选出最棒的作品进入决赛(现场答辩+陈述环节,由评委现场打分).终于排名由"初赛分数+现场答辩分"决定. ...
- python实现同服站点地址获取
说明:程序使用http://s.tool.chinaz.com/same此站点查询的结果.使用python简单的实现抓取结果 先随便查询一个结果,抓包分析,如图: 使用python模仿post表单,使 ...