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, ...
随机推荐
- JSP基础知识➣客户端请求与服务端响应(三)
JSP客户端请求 浏览器请求服务器端,信息头的一些重要内容,在以后的网络编程中将会经常见到这些信息: Accept:指定浏览器或其他客户端可以处理的MIME类型.它的值通常为 image/png 或 ...
- nginx 日志 cron任务切割日志
#vim cut_nginx_log.sh #cd /usr/local/nginx/logs/ #/bin/mv access.log access_$(date +%F).log #/usr/lo ...
- linux shell基本知识
shell script的一些注意事项: .#这个符号是注释本行,通常用来做批注用,#!除外,是用来标注用哪种shell执行本脚本, .执行顺序为从上到下,从做到右 .忽略空行,tab空格 .脚本换行 ...
- 实际生产用法CMS和G1
java -Xms100m -Xmx100m -Xmn50m -XX:MetaspaceSize=20m -XX:MaxMetaspaceSize=20m -XX:+UseConcMarkSweepG ...
- 谈谈Nginx-HTTPS加密技术
超文本传输安全协议(HTTPS)是以安全为目标的HTTP通道,简单来说就是HTTP安全版.https由两个部分组成:HTTP+SSL/TLS,在http基础上加上了一层加密信息模块,服务端和客户端的信 ...
- Python学习(二) —— 运算符
一:Python的编码 python2的默认编码是ascii码,而python3的默认编码是utf-8 ASCII(American Standard Code for Information Int ...
- Codeforces 316E3 线段树 + 斐波那切数列 (看题解)
最关键的一点就是 f[ 0 ] * a[ 0 ] + f[ 1 ] * a[ 1 ] + ... + f[ n - 1] * a[ n - 1] f[ 1 ] * a[ 0 ] + f[ 2 ] * ...
- 伪分布式hbase2.6.5和hbase1.1.2的配置
1.注意hadoop和hbase的版本兼容问题 目前测试用:hadoop 2.6.5 Hbase 1.1.2 2.创建hadoop用户 Sudo useradd –m hadoop –s /bin/ ...
- jquery的div局部刷新
jquery的div局部刷新 //div的局部刷新 $(".dl").load(location.href+" .dl"); 全页面的刷新方法 window.l ...
- 复制数组之System.arraycopy()的使用
System.arraycopy(src, srcPos, dest, destPos, length); [参数说明](注:arraycopy是一个古老的方法,从jdk1.0就有了,而当时命名并不规 ...