题目链接:

https://vjudge.net/problem/POJ-3669

题目大意:

巨大流星雨即将袭来。每个流星会对击中的地方以及周围(上下左右四格)造成破坏。Bessie开始时位于(0, 0)位置,并希望逃到一处不会被袭击到的地方(在第一象限内)。已知每移动一格需要1个时间单位,被流星破坏后的地方不能再进入。给出M个流星在T时刻击中的地方(X, Y),问Bessie能否逃到安全的地方,若能输出最短时间,否则输出-1。

思路:

预处理出每个点的最小爆炸时间,然后从(0,0)开始BFS,注意一个坑点,如果0时刻炸到了0 0 点那就直接输出-1,还有一个坑点就是不能局限于300*300的MAP,300*300的边界会WA,301*301的边界就过了,是因为的流星炸到300*300以内,肯需要逃离到301那一行才行

 #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
using namespace std;
typedef pair<int, int> Pair;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int T, n, m, d;
const int maxn = 1e5 + ;
int Map[][];//Map[i][j]表示ij这个点的最短
int dir[][] = {,,,,-,,,-};
bool vis[][];
struct node
{
int x, y, time;
node(int x, int y, int time):x(x), y(y), time(time){}
node(){}
};
int bfs()
{
queue<node>q;
q.push(node(,,));
vis[][] = ;
while(!q.empty())
{
node now = q.front();
q.pop();
//cout<<now.x<<" "<<now.y<<" "<<now.time<<endl;
if(Map[now.x][now.y] == INF)
{
return now.time;
}
for(int i = ; i < ; i++)
{
int xx = now.x + dir[i][];
int yy = now.y + dir[i][];
node next(xx, yy, now.time + );
if(xx < || xx > || yy < || yy > )continue;
if(vis[xx][yy])continue;
if(Map[xx][yy] <= next.time)continue;
vis[xx][yy] = ;
q.push(next);
}
}
return -;
}
int main()
{
cin >> n;
int x, y, w;
memset(Map, INF, sizeof(Map));
for(int i = ; i < n; i++)
{
scanf("%d%d%d", &x, &y, &w);
Map[x][y] = min(Map[x][y], w);
for(int i = ; i < ; i++)
{
int xx = x + dir[i][];
int yy = y + dir[i][];
if(xx >= && yy >= )
Map[xx][yy] = min(Map[xx][yy], w);
}
}
if(Map[][] == )//特判
{
cout<<"-1"<<endl;
return ;
}
cout<<bfs()<<endl;
return ;
}

POJ-3669 Meteor Shower---BFS+预处理的更多相关文章

  1. POJ 3669 Meteor Shower BFS求最小时间

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31358   Accepted: 8064 De ...

  2. POJ 3669 Meteor Shower BFS 水~

    http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...

  3. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  4. POJ 3669 Meteor Shower (BFS+预处理)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  5. POJ 3669 Meteor Shower【BFS】

    POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...

  6. poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  7. 题解报告:poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  8. poj 3669 Meteor Shower

                                                                                                      Me ...

  9. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  10. poj3669 Meteor Shower(BFS)

    题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... #include& ...

随机推荐

  1. ScheduledThreadPoolDemo01

    package com.zhy.concurrency.timer; import java.util.Date; import java.util.Timer; import java.util.T ...

  2. oracle截取字符串,定索引

    转载:https://www.cnblogs.com/qmfsun/p/4493918.html 使用Oracle中Instr()和substr()函数: 1 2 3 4 5 6 7 8 9 10 1 ...

  3. Flex布局教程

    一.Flex布局是什么? Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性.任何一个容器都可以指定为 Flex 布局. .box{ ...

  4. es6.3学习笔记

    es版本发布相当快,从1.x到2.x,再直接到5.x,6.x 索引这个词在es中有多重意思: 索引(名词):一个索引类似于传统数据库中的一个索引,用于存储关系型文档.索引的复数为indexes或ind ...

  5. 进入BIOS的步骤

    查看自己的BIOS版本 $ systeminfo 对号入座,电脑进入BIOS的两种实用方法

  6. C++的静态Static

    类的静态数据成员是属于类(即与类关联)而不属于类的每个对象(不与类的每个对象关联)(相当于该静态对象在所有的类对象中共享.),所以初始化方法与一般的变量不同,需要在类的构造函数之外进行初始化. 类的静 ...

  7. drop_caches控制page cache

    drop_caches Writing to this will cause the kernel to drop clean caches, as well as reclaimable slab ...

  8. Kudu和HBase定位的区别

    不多说,直接上干货! Kudu和HBase定位的区别 Kudu 的定位是提供 “ast analytics on fast data” ,也就是在快速更新的数据上进行快速的查询.它定位 OLAP 和少 ...

  9. 使用taobao的npm镜像源,同时安装nrm镜像工具

    身在天朝.你面临的一个问题就是网络 安装好Nodejs 控制台 执行 npm config set registry https://registry.npm.taobao.org //配置指向源 然 ...

  10. URAL 1145—— Rope in the Labyrinth——————【求树的直径】

    Rope in the Labyrinth Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...