【BZOJ】1611: [Usaco2008 Feb]Meteor Shower流星雨(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1611
一眼题,bfs。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=305, fx[]={-1, 1, 0, 0}, fy[]={0, 0, -1, 1}, oo=~0u>>1, Q=95000;
int mp[N][N], front, tail, n, vis[N][N];
struct ND { int x, y, d; }q[Q];
int main() {
read(n);
int x, y, z, dx, dy;
for1(i, 1, N-1) for1(j, 1, N-1) mp[i][j]=oo;
for1(i, 1, n) {
read(x); read(y); read(z);
++x; ++y;
mp[x][y]=min(mp[x][y], z);
rep(j, 4) {
dx=x+fx[j]; dy=y+fy[j];
mp[dx][dy]=min(mp[dx][dy], z);
}
}
ND t={1, 1, 0};
q[tail++]=t;
while(front!=tail) {
t=q[front++]; if(front==Q) front=0;
x=t.x; y=t.y; z=t.d;
if(mp[x][y]==oo) { printf("%d\n", z); return 0; }
rep(i, 4) {
dx=x+fx[i]; dy=y+fy[i];
if(dx<1 || dy<1 || mp[dx][dy]<=z+1 || vis[dx][dy]) continue;
if(mp[dx][dy]==oo) { printf("%d\n", z+1); return 0; }
vis[dx][dy]=1;
q[tail].x=dx; q[tail].y=dy; q[tail++].d=z+1;
if(tail==Q) tail=0;
}
}
puts("-1");
return 0;
}
Description
Input
Output
Sample Input
0 0 2
2 1 2
1 1 2
0 3 5
输入说明:
一共有4颗流星将坠落在霸中,它们落地点的坐标分别是(0, 0),(2, 1),(1, 1)
以及(0, 3),时刻分别为2,2,2,5。
t = 0 t = 2 t = 5
5|. . . . . . . 5|. . . . . . . 5|. . . . . . .
4|. . . . . . . 4|. . . . . . . 4|# . . . . . .
* = 流星落点
3|. . . . . . . 3|. . . . . . . 3|* # . . . . .
2|. . . . . . . 2|. # # . . . . 2|# # # . . . .
# = 行走禁区
1|. . . . . . . 1|# * * # . . . 1|# # # # . . .
0|B . . . . . . 0|* # # . . . . 0|# # # . . . .
-------------- -------------- --------------
0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6
Sample Output
输出说明:
如果我们观察在t=5时的霸中,可以发现离芙蓉哥哥最近的安全的格子是
(3,0)——不过由于早在第二颗流星落地时,芙蓉哥哥直接跑去(3,0)的路线就被封死了。
离芙蓉哥哥第二近的安全格子为(4,0),但它的情况也跟(3,0)一样。再接下来的格子就是在
(0,5)-(5,0)这条直线上。在这些格子中,(0,5),(1,4)以及(2,3)都能在5个单位时间内到达。
5|. . . . . . .
4|. . . . . . .
3|3 4 5 . . . . 某个合法的逃生方案中
2|2 . . . . . . 芙蓉哥哥每个时刻所在地点
1|1 . . . . . .
0|0 . . . . . .
--------------
0 1 2 3 4 5 6
HINT
Source
【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流星雨【BFS】
t记录每个格子最早被砸的时间,bfs(x,y,t)表示当前状态为(x,y)格子,时间为t.因为bfs,所以先搜到的t一定小于后搜到的,所以一个格子搜一次就行 #include<iostream& ...
- 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 ...
- [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 ...
随机推荐
- windows server 2008 安装Microsoft ActiveSync 6.1提示缺少一个Windows Mobile设备中心所须要的Windows组件
windows server 2008 安装WinCE的同步软件,须要安装Microsoft ActiveSync 6.1版本号的. 而不能安装ActiveSync|Microsoft ActiveS ...
- LInux下inode空间报警-CROND出错导致/var/spool/postfix/maildrop/堆积
Linux下显示磁盘空间不足,,通过 df -ih 查询发现/dev/mapper/*****var 下的inode用满.inode介绍 通过 du -sh * 查询/目录下的问题,最终查到/var/ ...
- Java 同步器
CyclicBarrier是什么 CyclicBarrier也叫同步屏障,在JDK1.5被引入,可以让一组线程达到一个屏障时被阻塞,直到最后一个线程达到屏障时,所以被阻塞的线程才能继续执行.Cycli ...
- myDate97 设置开始时间和结束时间
myDate97 设置开始时间和结束时间 CreationTime--2018年8月28日16点46分 Author:Marydon 1.简单示例 第一步:引入My97DatePicker/Wda ...
- [MSP430]入门之中的一个 总体认识
这是由TI公司推出的一款比較单片机, 相对stm32来说简单些, 由于它是16位的, 所以我们在学习中可能也会像51一样, 直接操纵寄存器. TI设计这款单片机的初衷是, 让它用于低功耗的嵌入式设 ...
- Apache 整合 Acitve Directory 達成 one single signon
原文地址:http://blog.hsdn.net/1266.html 我的公司使用AD進行使用者驗證,因此在使用者操作的便利性考量前提下.如何讓使用者不需要重覆輸入帳號與密碼,而直接抓取使用者已經登 ...
- web站点,同一个浏览器只能登陆一个用户的原因(cookie不能跨浏览器)
我的web站点,比如 http://ip/testsite/default.aspx, 当我在我的机器上,用chrome打开,用账号user1登陆,那么当我再新开个tab,再打开这个web站点,这时 ...
- mosquitto --用户配置 及权限管理
mosquitto中可以添加多个用户,只有使用用户名和密码登陆服务器才允许用户进行订阅与发布操作.可以说用户机制是mosquitto重要的安全机制,增强服务器的安全性.用户与权限配置需要修改3处地方: ...
- 实现WinForm窗体的美化(借助第三方控件)
在winform项目中,其实皮肤就是一个第三方的控件,名字是IrisSkin4.dll只要添加到你的工具箱里就可以和其它控件一样使用了 一.添加控件IrisSkin4.dll.方法: 先把IrisSk ...
- lintcode---线段树查询||(区间元素个数)
对于一个数组,我们可以对其建立一棵 线段树, 每个结点存储一个额外的值 count 来代表这个结点所指代的数组区间内的元素个数. (数组中并不一定每个位置上都有元素) 实现一个 query 的方法,该 ...