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, ...
随机推荐
- Maya闪退
电脑上装的Maya2015突然就打不开了,窗口闪一下就关闭,也没有任何提示. 将15卸载装了Maya2016还是一样. 再彻底卸载16,装了15,还不行... 将系统环境变量中PYTHONHOME和P ...
- Nodejs通过账号密码连接MongoDB数据库
转自https://blog.csdn.net/szu_lzz/article/details/77435804#commentBox 1.创建管理员 首先开启Mongo服务,然后切换admin数据库 ...
- .net core 中的 DependencyInjection - IOC
概要:因为不知道写啥,所以随便找个东西乱说几句,嗯,就这样,就是这个目的. 1.IOC是啥呢? IOC - Inversion of Control,即控制反转的意思,这里要搞明白的就是,它是一种思想 ...
- ssh连接时提示THE AUTHENTICITY OF HOST XX CAN’T BE ESTABLISHED
ssh链接云主机: ssh root@123.59.xx.xx 报错:THE AUTHENTICITY OF HOST XX CAN’T BE ESTABLISHED 解决办法: ssh -o Str ...
- JQuery函数大全
$(”p”).addClass(css中定义的样式类型); 给某个元素添加样式 $(”img”).attr({src:”test.jpg”,alt:”test Image”}); 给某个元素添加属性/ ...
- UOJ#23. 【UR #1】跳蚤国王下江南 仙人掌 Tarjan 点双 圆方树 点分治 多项式 FFT
原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ23.html 题目传送门 - UOJ#23 题意 给定一个有 n 个节点的仙人掌(可能有重边). 对于所有 ...
- POJ 1284 Primitive Roots (欧拉函数+原根)
<题目链接> 题目大意: 满足{ ( $x^{i}$ mod p) | 1 <=$i$ <= p-1 } == { 1, …, p-1 }的x称为模p的原根.给出p,求原根个数 ...
- Ubuntu ssh-keygen 生成公钥并添加到远程服务器上
1. 在本地生成公钥, ssh-keygen -t RSA -b 800 2. cd /root/.ssh 3. ssh-copy-id -i id_rsa.pub 远程服务器IP 这一步需要输入远 ...
- 001.Amoeba读写分离部署
一 Amoeba简介 Amoeba(变形虫)项目,该开源框架于2008年 开始发布一款 Amoeba forMysql软件.这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQ ...
- Flutter - Migrate to AndroidX
一段时间没玩Flutter,今天打开一个项目编译了一下,突然发现不能编译了,出现 Launching lib\main.dart on Nokia X6 in debug mode... FAILUR ...