【POJ - 3669】Meteor Shower(bfs)
-->Meteor Shower
直接上中文了
Descriptions:
Bessie听说有场史无前例的流星雨即将来临;有谶言:陨星将落,徒留灰烬。为保生机,她誓将找寻安全之所(永避星坠之地)。目前她正在平面坐标系的原点放牧,打算在群星断其生路前转移至安全地点。
此次共有M (1 ≤ M ≤ 50,000)颗流星来袭,流星i将在时间点Ti (0 ≤ Ti ≤ 1,000) 袭击点 (Xi, Yi) (0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 300)。每颗流星都将摧毁落点及其相邻四点的区域。
Bessie在0时刻时处于原点,且只能行于第一象限,以平行与坐标轴每秒一个单位长度的速度奔走于未被毁坏的相邻(通常为4)点上。在某点被摧毁的刹那及其往后的时刻,她都无法进入该点。
寻找Bessie到达安全地点所需的最短时间。
Input
* 第2..M+1行: 第i+1行包含由空格分隔的三个整数: Xi, Yi, and Ti
Output
* 仅一行: Bessie寻得安全点所花费的最短时间,无解则为-1。
Sample Input
4
0 0 2
2 1 2
1 1 2
0 3 5
Sample Output
5
题目链接:
https://vjudge.net/problem/POJ-3669
题目没给地图,但是自己要会做地图
题目要求的是流星坐标(0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 300),而人的坐标只能行于第一象限,所以人可以X>300,Y>300
首先把流星落到(x,y)的时间全部展现在地图mp[i][j]中,然后人从(0,0)开始出发,dfs,找到没有落流星的地方即可
AC代码:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 310
using namespace std;
struct node
{
int x,y,t;//坐标,时间
};
node now,net;
queue<node>q;
int m;
int x,y,t;
int mp[Maxn][Maxn];//存每一个坐标的时间
int dt[][]= {{,},{-,},{,},{,-},{,}};//连带即自己5个方向
int bfs()
{
if(mp[][]==-)//起始点没落过流星,这里安全,不用走
return ;
if(mp[][]==)//起始点在时间t=0时就被落过流星,没开始走就挂了
return -;
now.x=,now.y=,now.t=;//初始化起点
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
for(int i=;i<;i++)//人走四个方向
{
net.x=now.x+dt[i][];
net.y=now.y+dt[i][];
net.t=now.t+;
if(net.t<||net.y<)//题目要求人只能行于第一象限,即x和y可以大于300
continue;
if(mp[net.x][net.y]==-)//这里没落过流星 安全 不用走了
return net.t;
if(net.t>=mp[net.x][net.y])//到这里的时间>=流星落在这里的时间,不安全
continue;
mp[net.x][net.y]=net.t;//到这里的时间<流星落在这里的时间,暂时安全,还要继续走
q.push(net);
}
}
return -;
}
int main()
{
MEM(mp,-);
cin>>m;
while(m--)
{
cin>>x>>y>>t;
for(int i=;i<;i++)//mp存放每个流星落点附近点的时间最小值
{
int tx=x+dt[i][];
int ty=y+dt[i][];
if(tx<||tx>||ty<||ty>)//题目要求(0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 300)
continue;
if(mp[tx][ty]==-)//没落过流星
mp[tx][ty]=t;
else//已经有过流星,取最小值
mp[tx][ty]=min(t,mp[tx][ty]);
}
}
cout<<bfs()<<endl;
}
【POJ - 3669】Meteor Shower(bfs)的更多相关文章
- 【POJ 2251】Dungeon Master(bfs)
BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...
- 【POJ - 3126】Prime Path(bfs)
Prime Path 原文是English 这里直接上中文了 Descriptions: 给你两个四位的素数a,b.a可以改变某一位上的数字变成c,但只有当c也是四位的素数时才能进行这种改变.请你计算 ...
- 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 ...
- poi 3669 meteor shower (bfs)
题目链接:http://poj.org/problem?id=3669 很基础的一道bfs的题,然而,我却mle了好多次,并且第二天才发现错在了哪里_(:з)∠)_ 写bfs或者dfs一定要记得对走过 ...
- 【POJ 1273】Drainage Ditches(网络流)
一直不明白为什么我的耗时几百毫秒,明明差不多的程序啊,我改来改去还是几百毫秒....一个小时后:明白了,原来把最大值0x3f(77)取0x3f3f3f3f就把时间缩短为16ms了.可是为什么原来那样没 ...
- BZOJ 2296【POJ Challenge】随机种子(构造)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2296 [题目大意] 给出一个数x,求一个10的16次以内的数使得其被x整除并且数字包含 ...
- 【POJ - 3984】迷宫问题(dfs)
-->迷宫问题 Descriptions: 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
随机推荐
- DataTable转换为Entity(反射&&泛型)
public static IEnumerable<T> Parse<T>(IEnumerable<DataRow> rows) where T : class, ...
- JS 中按键处理
<script type="text/javascript"> //关于键的问题 onload = function () { ...
- 【Gerrit】Performance Cheat Sheet
首先说下做这件事情的主因,组内有人说Project repo sync有点慢,废话不多说,直接上图. 相关官方文档参考链接: 我的数据: ~/review_site/logs# fgrep " ...
- C#程序以管理员的身份运行
在一些特定的情况下我们需要能够有管理员的权限,这样我们的很多执行,或者写入就不会报错了. 1.解决方案资源管理器---->项目(右键)--->属性-->安全性 2.勾选“启用Clic ...
- 传入字典的模型项的类型为“System.Boolean”,但此字典需要类型“InternalCRM.EntityIACrm.Template”的模型项。
“/”应用程序中的服务器错误. 传入字典的模型项的类型为“System.Boolean”,但此字典需要类型“InternalCRM.EntityIACrm.Template”的模型项. 说明: 执行当 ...
- MiTeC System Information Component Suite 10.9.2 D5-XE3 Full Source
The most complex system information probe in Delphi world, it consists of many standalone components ...
- 什么是Android NDK
1.NDK是一系列工具的集合. NDK提供了一系列的工具,帮助开发者快速开发C(或C++)的动态库,并能自动将so和java应用一起打包成apk.这些工具对开发者的帮助是巨大的. NDK集成了交叉编译 ...
- 20 个免费开源的 CSS3 用户界面工具包
ui.css Metro UI CSS Pure CSS jQuery jKit Solid HTML5/CSS3 UI Kit CSS3 UI Kit Alt CSS3 UI Kit MediaLo ...
- springboot中加分布式redis锁
分布式redis锁,spring-boot-starter-data-redis,RedisTemplate 公司聊天的聊天系统,近期出现多个客服并发接待同一个客户的记录,经排查,是由于代码加的同步锁 ...
- LR编写Socket脚本方法1(XML/16进制报文data.ws格式)
本文主要讲述了Socket协议脚本的基础知识和编写方法,让大家能够在短时间内快速掌握简单的Socket协议脚本的编写方法.1.socket协议介绍Socket协议有万能协议之称,很多系统底层都是用的s ...