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 ...
随机推荐
- python标准库笔记
1.python互联网数据处理模块 base64数据编码 二进制数据 encode ASCII字符 ASCll字符 decode 二进制数据 json数据交换格式 轻量的数据交换格式,json暴露的A ...
- MTK android L使用汇顶TP如何使用B协议
使用B协议上报之前的代码: #include "tpd.h" #include "tpd_custom_gt9xx.h" #ifndef TPD_NO_GPIO ...
- TCP/IP学习笔记(5)------IP选路
静态IP选路 一个简单的路由表 选路是IP层最重要的一个功能之一.前面的部分已经简单的讲过路由器是通过何种规则来根据IP数据包的IP地址来选择路由.这里就不重复了.首先来看看一个简单的系统路由表. D ...
- 学习日常笔记<day09>Http协议
1 Http协议入门 1.1 什么是http协议 http协议: 对浏览器客户端 和 服务器端 之间数据传输的格式规范 1.2 查看http协议的工具 1)使用火狐的firebug插件(右键-> ...
- [转]Attribute在.net编程中的应用
Attribute在.net编程中的应用(一) Attribute的基本概念 经常有朋友问,Attribute是什么?它有什么用?好像没有这个东东程序也能运行.实际上在.Net中,Attribute是 ...
- 移动端 js 实现图片上传 预览
方法一: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=&q ...
- 实战!利用MSF批量扫描校园网中含有MS17_010漏洞的主机并入侵
利用ms17_010的永恒之蓝在前些日子火爆了一段时间,校园网中也声称封锁了相应端口.最近在搞MSF的深入学习,于是有了下文. ms17_010扫描工具 msf中的辅助模块含有一个强大的ms17_01 ...
- pageContext 获取Session 为null原因
问题:在J2EE应用中.发如今自己定义标签中取不到session: HttpSession session = pageContext.getSession(); 你会发现session的值可能是空的 ...
- 小白学开发(iOS)OC_ 字符串的获取 (2015-08-11)
// // main.m // 字符串的获取 // // Created by admin on 15/8/13. // Copyright (c) 2015年 admin. All righ ...
- Cocos2d-X中的ProgressTimer
ProgressTimer即进度条,进度条在游戏开发中运用很广泛,比如在一些格斗游戏中,显示血液的变化,还有游戏载入进度,等都离不开进度条 Cocos2d-X中使用CCProgressTimer ...