poj3669 Meteor Shower(预处理+bfs)
https://vjudge.net/problem/POJ-3669
先给地图a[][]预处理每个位置被砸的最小时间。然后再bfs。
纯bfs,还被cin卡了下时间。。
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
using namespace std;
int a[][], vis[][];
int dir[][] = {, , , -, , , -, };
typedef struct{
int a, b;
int step;
}Node;
Node node;
void bfs()
{
queue<Node> q;
node.a = ; node.b = ;
node.step = ;
q.push(node);
vis[][] = ;
while(!q.empty()){
Node t = q.front(), p;
if(a[t.a][t.b] == INF){
cout << t.step << endl;
break;
}
for(int i = ; i < ; i++){
int tx = t.a + dir[i][];
int ty = t.b + dir[i][];
if(tx>=&&ty>=&&!vis[tx][ty]){
if(t.step+<a[tx][ty]){
p.a = tx; p.b = ty;
p.step = t.step+;
vis[tx][ty] = ;
q.push(p);
}
}
}
q.pop();
}
if(q.empty()){
cout << "-1" << endl;
}
}
int main()
{
IO;
int m, x, y, t;
memset(vis, , sizeof(vis));
for(int i = ; i < ; i++){
for(int j = ; j < ; j++){
a[i][j] = INF;
}
}
cin >> m;
for(int i = ; i < m; i++){
cin >> x >> y >> t;
a[x][y] = min(a[x][y], t);
for(int j = ; j < ; j++){
int tx = x + dir[j][];
int ty = y + dir[j][];
if(tx>=&&ty>=){
a[tx][ty] = min(a[tx][ty], t);
}
}
}
/*for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
cout << a[i][j] << " " ;
}
cout << endl;
}*/
bfs();
return ;
}
poj3669 Meteor Shower(预处理+bfs)的更多相关文章
- poj3669 Meteor Shower(BFS)
题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... #include& ...
- POJ3669(Meteor Shower)(bfs求最短路)
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12642 Accepted: 3414 De ...
- 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)
-->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...
- 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(bfs)
http://poj.org/problem?id=3669 注意理解题意:有m颗行星将会落在方格中(第一象限),第i颗行星在ti时间会摧毁(xi,yi)这个点和四周相邻的点,一个人开始在原点,然后只 ...
- [Usaco2008 Feb]Meteor Shower流星雨[BFS]
Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的 ...
- POJ-3669 Meteor Shower---BFS+预处理
题目链接: https://vjudge.net/problem/POJ-3669 题目大意: 巨大流星雨即将袭来.每个流星会对击中的地方以及周围(上下左右四格)造成破坏.Bessie开始时位于(0, ...
随机推荐
- python导入import
1.参考 Python 相对导入与绝对导入 2.Python import 的搜索路径 在当前目录下搜索该模块 在环境变量 PYTHONPATH 中指定的路径列表中依次搜索 在 Python 安装路径 ...
- ubuntud安装Adobe Flash Player / Plugin
1.https://get.adobe.com/flashplayer/ , select tar.gz for other Linux, download 2.Unpack the tar.gz f ...
- 使用htpasswd及nginx auth模块对指定页面进行登录验证
某些时候,作为运维挂你人员会部署一些工具用于使用外网对内部服务器进行某些管理,比如phpmyadmin.gateone堡垒机等工具.但是这些软件 一旦部署之后,所有人都可以访问到我们的登录页面似乎并不 ...
- 【Android】Android模拟器快速root
启动Android模拟器,开始-运行-输入cmd,运行命令行 adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system ...
- Logstash过滤分析日志数据/kibanaGUI调试(四)
[Logstash] [root@localhost ~]# wget https://artifacts.elastic.co/downloads/logstash/logstash-6.3.2.t ...
- idea maven项目打war包 以及项目重新部署
第一步 打war包: 这样war报就在你项目的target目录下: 第二步 部署步骤 首先进入服务器tomcat bin 目录 关闭服务 命令: ./shutdown.sh 然后就要进入webap ...
- js,JQ获取短信验证码倒计时
按钮 <a href="javasript:void(0);"onclick="settime(this);">获取手机验证码</a> ...
- Django之Form组件(一)
Django之Form组件(一) Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 基本操作:字 ...
- 深入理解JS防抖与节流
参考博客:JS防抖和节流,感谢作者的用心分享 日常开发过程中,滚动事件做复杂计算频繁调用回调函数很可能会造成页面的卡顿,这时候我们更希望把多次计算合并成一次,只操作一个精确点,JS把这种方式称为deb ...
- 上海市2019年公务员录用考试笔试合格人员笔试成绩(A类)
考试类别:A类 注册编号 总成绩 注册编号 总成绩 注册编号 总成绩 注册编号 总成绩 4016574 127.4 5112479 145.9 5125732 124.3 5141074 159.9 ...