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& ...
随机推荐
- Ubuntu14上安装Mongo3.2
1. 安装 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D68FA50FEA312927 echo "deb ...
- Spring Boot如何初始化数据
Hibernate机制:classpath下的import.sql,l在ddl-auto是create和create-drop时自动执行,如果ddl-auto设置为update就不合适,所以此选项不适 ...
- 7.Hibernate 检索
1.Hibernate检索方式 检索方式简介: 导航对象图检索方式:根据已经加载的对象,导航到其他对象.OID检索方式:按照对象的OID来检索对象.Session 的 get() 和 load() 方 ...
- Day04 流程控制 while 和for循环
一.流程控制 if 判断 python中使用缩进来区分代码块的 语法 一: #python if 条件: 代码块1 代码块2 自上而下依次运行 语法二: # python if 条件一: 代码一 el ...
- 虚拟机 ---- 最小化安装无法使用tab补全键
解决方法: 安装 yum -y install bash-completion 然后重启 注意:挂载时使用绝对路径的cdrom挂载, ls -l /dev/cdromvim /etc/fstab — ...
- transient关键字与序列化、反序列化
transient,中文翻译是短暂的,和对象序列化.反序列化有关. 一个类只要实现了Serializable接口,则该类实例就可以序列化,具体来说实例的每个非静态成员变量都会序列化.注意是非静态成员变 ...
- 使用Dockerfile docker tomcat部署
在百度上试很多文章都不行,只有这篇可以. 宿主机为:centos64位 //安装docker 1:yum install docker //启动docker 2:systemctl start do ...
- linux_api之进程控制
本篇索引: 1.引言 2.进程标识 3.多进程 4.fork函数 5.vfork函数 6.exit函数 7.wait和waitpid函数 8.竞态 9.exec函数族 10.进程状态 11.syste ...
- oracle expdp impdp 数据泵方式
一.不管导入还有导出都要先创建目录 1.登录plsql sqlplus/nolog conn sys/dbwork@orcl 2.创建目录 create directory my_dir as 'd: ...
- JavaScript 数组(Array)
//声明方式 //调用 Array构造函数创建并赋值 var users = new Array(); //new 可以省略 ); //new 可以省略 var users3 = new Array( ...