[Usaco2008 Feb]Meteor Shower流星雨
去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的一切东西造成毁灭性的打击。很自然地,芙蓉哥哥开始担心自己的 安全问题。以霸中至In型男名誉起誓,他一定要在被流星砸到前,到达一个安全的地方 (也就是说,一块不会被任何流星砸到的土地)。如果将霸中放入一个直角坐标系中, 芙蓉哥哥现在的位置是原点,并且,芙蓉哥哥不能踏上一块被流星砸过的土地。根据预 报,一共有M颗流星(1 <= M <= 50,000)会坠落在霸中上,其中第i颗流星会在时刻 T_i (0 <= T_i <= 1,000)砸在坐标为(X_i, Y_i) (0 <= X_i <= 300;0 <= Y_i <= 300) 的格子里。流星的力量会将它所在的格子,以及周围4个相邻的格子都化为焦土,当然 芙蓉哥哥也无法再在这些格子上行走。芙蓉哥哥在时刻0开始行动,它只能在第一象限中, 平行于坐标轴行动,每1个时刻中,她能移动到相邻的(一般是4个)格子中的任意一个, 当然目标格子要没有被烧焦才行。如果一个格子在时刻t被流星撞击或烧焦,那么芙蓉哥哥 只能在t之前的时刻在这个格子里出现。请你计算一下,芙蓉哥哥最少需要多少时间才能到 达一个安全的格子。
这题一看就是BFS即可。纯暴力
不过需要注意的是,人可以走的坐标并没有做限定。也就是说在(0,0) ----(300,300) 这个区域外的任何坐标都是安全的。这点需要注意
另外还要判断人刚开始所处的位置是否安全
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <ctime>
#define INF 1000000007
using namespace std;
int v[333][333];
int m;
int vis[333][333];
int xx[] = {0, 0, -1, 1};
int yy[] = {1, -1, 0, 0};
struct node
{
int x, y, num;
node(){}
node(int _x, int _y, int _num){x = _x; y = _y; num = _num;}
};
queue<node>q;
void bfs()
{
node now = node(0, 0, 0);
vis[0][0] = 1;
if(v[0][0] > 0) q.push(now);
int ans = -1;
while(!q.empty())
{
now = q.front();
q.pop();
if(v[now.x][now.y] == INF)
{
ans = now.num;
break;
}
for(int i = 0; i < 4; i++)
{
int tx = now.x + xx[i];
int ty = now.y + yy[i];
if(tx < 0 || ty < 0) continue;
if(now.num + 1 < v[tx][ty] && !vis[tx][ty])
{
vis[tx][ty] = 1;
q.push(node(tx, ty, now.num + 1));
}
}
}
printf("%d\n", ans);
}
int main()
{
int x, y, t;
for(int i = 0; i <= 330; i++)
for(int j = 0; j <= 330; j++)
v[i][j] = INF;
scanf("%d", &m);
while(m--)
{
scanf("%d%d%d", &x, &y, &t);
v[x][y] = min(t, v[x][y]);
if(x > 0) v[x - 1][y] = min(v[x - 1][y], t);
if(y > 0) v[x][y - 1] = min(v[x][y - 1], t);
v[x + 1][y] = min(v[x + 1][y], t);
v[x][y + 1] = min(v[x][y + 1], t);
}
bfs();
return 0;
}
[Usaco2008 Feb]Meteor Shower流星雨的更多相关文章
- BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 904 Solved: 393 ...
- BZOJ 1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个 ...
- 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年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的 ...
- 【BZOJ】1611: [Usaco2008 Feb]Meteor Shower流星雨(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1611 一眼题,bfs. #include <cstdio> #include <c ...
- BZOJ——1611: [Usaco2008 Feb]Meteor Shower流星雨
http://www.lydsy.com/JudgeOnline/problem.php?id=1611 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1 ...
- bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨【BFS】
t记录每个格子最早被砸的时间,bfs(x,y,t)表示当前状态为(x,y)格子,时间为t.因为bfs,所以先搜到的t一定小于后搜到的,所以一个格子搜一次就行 #include<iostream& ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- bzoj1611 / P2895 [USACO08FEB]流星雨Meteor Shower
P2895 [USACO08FEB]流星雨Meteor Shower 给每个点标记一下能够走的最迟时间,蓝后bfs处理一下 #include<iostream> #include<c ...
随机推荐
- C#根据域名查询IP(CMD命令参数输入或者启动程序后再输入查询)
有时因为需要,希望知道域名的IP,那用C#怎么实现呢?以下是实现代码 using System; using System.Collections.Generic; using System.Linq ...
- [译]URL和URI的区别
译者:华科小涛:http://www.cnblogs.com/hust-ghtao/: 初学http协议,就被这两个相似的术语搞蒙了,查了很多资料,总算搞清楚了.(找资料还是英文啊,靠谱...). 本 ...
- JVM调优总结(九)-新一代的垃圾回收算法
垃圾回收的瓶颈 传统分代垃圾回收方式,已经在一定程度上把垃圾回收给应用带来的负担降到了最小,把应用的吞吐量推到了一个极限.但是他无法解决的一个问题,就是Full GC所带来的应用暂停.在一些对实时性要 ...
- OGR API Tutorial
This document is intended to document using the OGR C++ classes to read and write data from a file. ...
- IOS学习之segmented control
转载请注明出处 http://blog.csdn.net/pony_maggie/article/details/27086877 作者:小马 什么是segmented control? 先上几张图: ...
- How to Create a Java Concurrent Program
In this Document Goal Solution Overview Steps in writing Java Concurrent Program Template ...
- 如何捕获winform程序全局异常?
1.在C#中我们如何处理异常? 上面的问题学过C#的问题大家可能都能回答处理,用try-catch-finally具体如下: try { //可能出错的语句 } catch (Exception) { ...
- 使用 Spring RestTemplate 调用 rest 服务时自定义请求头(custom HTTP headers)
在 Spring 3.0 中可以通过 HttpEntity 对象自定义请求头信息,如: private static final String APPLICATION_PDF = "app ...
- truncate 和 delete 差异
truncate table players; 相当于 delete from players;要么 delete players from players; 要么 delete players.* ...
- Github-Client(ANDROID)开源之旅(四) ------ 简介Roboguice
Guice是Google开发的一个轻量级,基于Java5(主要运用泛型与注释特性)的依赖注入框架(IOC),Guice非常小而且快.Guice是类型安全的,它能够对构造函数,属性,方法(包含任意个参数 ...