【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 ...
随机推荐
- Android画图最基本的三个对象(Color,Paint,Canvas)
Android画图最基本的三个对象(Color,Paint,Canvas) 三个类都存放在 android.graphics包下 1) Color :颜色对象,相当于现实生活中的 ‘调料’ 2) Pa ...
- MySQL 连接方式
MySQL 连接方式 1:TCP/IP 套接字方式 这种方式会在TCP/IP 连接上建立一个基于网络的连接请求,一般是client连接跑在Server上的MySQL实例,2台机器通过一个TCP/IP ...
- 编译VLC for IOS
之前接触VLC是因为Winrt的项目,后来似乎ARM版本的始终搞不定(没有针对于ARM-COFF的GCC编译器),vlc for winrt的项目好久没有更新了,自己也没有深入研究.有一天跟同事聊,他 ...
- java之final
我们先看一道面试题: 请问 final 的含义是什么?可以用在哪里?其初始化的方式有哪些? 首先我们回答一下这道题,然后再探究其所以然. 1.final 表示“最终的”.“不可改变的”,意指其修饰类 ...
- [HNOI2002]营业额统计 Splay tree
Splay tree入门题,学好代码风格,学习HH大牛的,传送门.. #include <functional> #include <algorithm> #include & ...
- JAVA中==与equals的区别
equals如果没有被重写的话,和==的作用是一样的,都是判断两个对象引用是否指向同一个地址.一般重写了equals()方法就表示比较它们“实际意义上相等”,比较的是内容,而不是引用地址.Java中S ...
- Decoration6:改数据结构为继承的关系
一个家装市场有各种登录的角色:设计师.业主…… 这些角色有一些共同的字段,例如passWord,userName,age等等,但是分别又有自己的一些特殊字段,例如设计师要写自己的设计经历,业主可能要有 ...
- 李洪强iOS开发之苹果企业开发者账号申请流程
李洪强iOS开发之苹果企业开发者账号申请流程 一. 开发者账号类型选择 邓白氏码 DUNS number,是Data Universal Numbering System的缩写,是一个独一无二的9位数 ...
- jquery衬衣产品内容详情页
html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- dubbo异步调用三种方式
异步通讯对于服务端响应时间较长的方法是必须的,能够有效地利用客户端的资源,在dubbo中,消费端<dubbp:method>通过 async="true"标识. < ...