POJ-3669 Meteor Shower---BFS+预处理
题目链接:
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+预处理的更多相关文章
- POJ 3669 Meteor Shower BFS求最小时间
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31358 Accepted: 8064 De ...
- POJ 3669 Meteor Shower BFS 水~
http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- 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】
POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...
- 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 3669 Meteor Shower
Me ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- poj3669 Meteor Shower(BFS)
题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... #include& ...
随机推荐
- nginx -s reload "/alidata/server/nginx/logs/nginx.pid" failed
[root@snoopy :: vhosts]# nginx -s reload nginx: [error] open() : No such file or directory) 修改完nginx ...
- python django bootstrap_导入 201901
参考 http://www.liujiangblog.com/course/django/124 AdminLTE-2.4.5 http://www.liujiangblog.com/course/d ...
- 分配一维动态数组or 二维动态数组的方法以及学习 new 方法or vector
先来个开胃菜 // 使用new动态分配存储空间 #include<iostream> using std::cout; int main() { // 第1种方式 int *a=new i ...
- 使用Faster R-CNN做目标检测 - 学习luminoth代码
像玩乐高一样拆解Faster R-CNN:详解目标检测的实现过程 https://mp.weixin.qq.com/s/M_i38L2brq69BYzmaPeJ9w 直接参考开源目标检测代码lumin ...
- Idea创建Maven项目没有src
第一次创建,下载非常慢,解决方法 1.配置环境变量 第二种:创建Maven项目时加上 archetypeCatalog=internal 参数 第三种:为自己的Maven配置国内镜像源 打开自己的 M ...
- DEDE模板中如何运行php脚本和php变量的使用
在使用dede模板的时候,经常会需要直接对dede数据库的底层字段进行处理,如果dede中没有相应的函数的时候,往往就需要我们想办法来处理了. 举例:我想取出数据表addonimages中的某一条记录 ...
- http method and status code
http method HEAD: 只返回相应的header POST: 一般用于提交表单 PUT: 向Web服务器上传文件 GET: 查 DELET: 删除 status code 1xx与2xx: ...
- VUE中给template组件加背景
<template> <div class="index_background" > </div> </template> < ...
- poj 1741 两点距离小于K(树DP)
http://blog.csdn.net/woshi250hua/article/details/7723400 求两点间距离小于等于k的方案数 理一下思路: 求通过点A与另一点连接符合条件的个数 = ...
- 巧用CSS属性visibility与opacity代替鼠标经过的jQuery事件
一直使用jQuery的hover()函数来写鼠标经过事件,这几天发现其他同行直接使用CSS就搞定了.自己在线下也试了试: 当然也并不是没有前提条件,需要配合一些定位属性来使用(position/top ...