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 ...
随机推荐
- 面试高峰期,如何应对面试官的jvm刁难,特写一篇jvm面经(第一部)
已经进入三月份,正所谓金三银四,正是一年最好的招聘期,想必我的公号粉丝们一定有不少想要跳槽的吧,哈哈,/**偷偷告诉你们其实小编也准备跳槽*/(我要加个注释,被老板知道可就完蛋了),说到面试,想必大家 ...
- xtu Shortest Path
Acceteped : 23 Submit : 61 Time Limit : 5000 MS Memory Limit : 65536 KB Description 题目描述 N(3≤N≤1 ...
- 郁闷的出纳员(bzoj 1503)
Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...
- android中后一个activity传值给前一个activity的实现
前一个activity跳转到后一个activity设置code: Intent intent=new Intent(MainActivity.this,ActivityTwo.class); star ...
- Spring Boot - how to configure port
https://stackoverflow.com/questions/21083170/spring-boot-how-to-configure-port
- 类(Class)
类 · 目的 面向对象的最主要目的是提高程序的重复使用性. · 包括 属性(attribute).方法(method) · 示例 class Bird(object): have_feather = ...
- python基础之-字符串
字符模块:strstr.strip():去掉字符串前后空格str.lstrip():去掉字符串左侧空格str.rstrip():去掉字符串右侧空格str.encode():将字符串编码为二进制str. ...
- 2017 CCPC 杭州 HDU6273J 区间修改(线段树&差分数组)
http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf 解析 线段树区间延迟更新 或 差分数组 两个数 统计2和3的最少的 ...
- poj_2524_Ubiquitous Religions_201407211506
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23390 Accepted: ...
- centos7grub2 引导win10
centos7+win10安装完成之后,使用gurb2引导win10系统 方式:使用ntfs-3g 步骤: 1.加源 wget -O /etc/yum.repos.d/epel.repo http: ...