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)的更多相关文章

  1. poj3669 Meteor Shower(BFS)

    题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... #include& ...

  2. POJ3669(Meteor Shower)(bfs求最短路)

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12642   Accepted: 3414 De ...

  3. POJ 3669 Meteor Shower (BFS+预处理)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  4. 【POJ - 3669】Meteor Shower(bfs)

    -->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...

  5. poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  6. 题解报告:poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  7. POJ-3669 Meteor Shower(bfs)

    http://poj.org/problem?id=3669 注意理解题意:有m颗行星将会落在方格中(第一象限),第i颗行星在ti时间会摧毁(xi,yi)这个点和四周相邻的点,一个人开始在原点,然后只 ...

  8. [Usaco2008 Feb]Meteor Shower流星雨[BFS]

    Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的 ...

  9. POJ-3669 Meteor Shower---BFS+预处理

    题目链接: https://vjudge.net/problem/POJ-3669 题目大意: 巨大流星雨即将袭来.每个流星会对击中的地方以及周围(上下左右四格)造成破坏.Bessie开始时位于(0, ...

随机推荐

  1. js条件语句初步练习

    var a=18            if(a<10){                alert("便宜")            }            else{  ...

  2. NEST 中的日期数学表达式

    Date math expressions Version: 5.x 英文原文地址:Date math expressions query/filter 中涉及到日期类型时(如:timeout 参数) ...

  3. k8s 廖老师的分享

    https://mp.weixin.qq.com/s/7o8QxGydMTUe4Q7Tz46Diw

  4. 利用Jmeter做接口测试的时候,如何提取头部的JSESSIONID然后传递到下一个请求,继续完成当前用户的请求。

    其实,关于这个问题有三种种解决方法: 1)从响应数据里面提取JSESSIONID,点击链接可以查看https://www.cnblogs.com/liulinghua90/p/5320290.html ...

  5. IntelliJ IDEA安装bower

    安装nodejs(x64) https://nodejs.org/en/ 设置环境变量 变量名 NODE_PATH 变量值 C:\Program Files\nodejs\node_modules p ...

  6. Service插件化解决方案

    --摘自<android插件化开发指南> 1.ActivityThread最终是通过Instrumentation启动一个Activity的.而ActivityThread启动Servic ...

  7. 关于pycharm中安装第三方库时报错的解决办法(一)

    记录自己的生活!   一.事发背景 在pycharm中直接安装第三方库时因为版本问题总是无法安装成功,事情不大,但是很重要.   二.经过 最开始我自己电脑上安装了Python3.6和Python2. ...

  8. ACM10.14题解

    ACM10.14题解 第一次打周赛,感觉还是比较紧张的,应该开完所有的题再做,而不是硬做,没必要硬杠英语,还是不要抱有侥幸心理,做对一定是完全理解且会,自己小心边界问题,不要瞎交. A:暴力明显不对嘛 ...

  9. spring boot默认访问静态资源

    演示spring boot默认可以直接访问静态资源的2种方法: 第一种:在src/main/resources资源目录下创建一个名为"static"的文件夹(该文件夹的名称是规定死 ...

  10. linux 学习笔记 TAR包管理

    >显示gong.tar 文件内容 #tar tf gong.tar ./epuinfo.txt ./smart/ ./smart/smartsuite-2.1-2.i386.rpm ./smar ...