【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 ...
随机推荐
- poj 2388 insert sorting
/** \brief poj 2388 insert sorting 2015 6 12 * * \param * \param * \return * */ #include <iostrea ...
- ubuntu执行级别,设置单用户模式
redhat的runlevel级别定义例如以下: 0:关机.不能将系统缺省执行级别设置为0,否则无法启动. 1:单用户模式.仅仅同意root用户对系统进行维护. 2:多用户模式.但不能使用NFS( ...
- js&jquery避免报错的方法
CreateTime--2016年12月8日15:28:40Author:Marydonjs&jquery规避报错信息的两种方式 <script type="text/ja ...
- 名词解释:alpha版、beta版、rc版的意思(转)
很多软件在正式发布前都会发布一些预览版或者测试版,一般都叫“beta版”或者 “rc版”,特别是开源软件,甚至有“alpha版”,下面来解释一下各个版本的意思. alpha版:内部测试版.α是希腊字母 ...
- JDBC 数据库连接池的简单实现
连接池代码: public class MyDataSource2{ private static String url = "jdbc:mysql://localhost:3306 ...
- Android开发之帐户管理
android.accounts主要包括了集中式的帐户管理API, AccountManagerCallback, AccountManagerFuture, OnAccountsUpdateList ...
- iOS开发-应用之间的跳转及通信
Update 2016-08-12: 在Github的Demo上增加Mac自定义Url Scheme,可以在Safari上输入特定协议头打开应用,并传递参数) 简介 我们接下来将要实现应用程序之间的跳 ...
- PHP-php.ini中文版
今天细看了下配置文件 有很多没用过的 就从网上搜了一篇 常看看 ;;;;;;;;;;;;;;;; 简介 ;;;;;;;;;;;;;;;;; 本文并非是对英文版 php.ini 的简单翻译,而是参考了众 ...
- cocopods卸载、安装、重装等问题解决(转)
今日在升级af库的时候,头脑发热把cocopods给卸载了,然后重装就出现了一些问题,主要是Mac ox s升级至10.11之后,好多命令都和以前不一样了,现在重新总结其安装步骤,如下: 一.全新安装 ...
- JNI调用之本地库文件的安装
在进行JNI调用的时候.是由java的本地接口调用本地库文件来完毕的,可是本地库文件须要放置到指定位置.JNI接口才干调用到,这个路径是由JVM的系统变量"java.library.path ...