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. sprintf补位

    有的时候需要00001这样的字符串 来源却是Int的1 这个时候就可以用sprintf方法了 $i = 3; $a=sprintf("%08d", $i); echo $a; %0 ...

  2. python之 MySQLdb 实践 爬一爬号码

    0.目录 2.构建URL3.新建数据库4.新建汇总表5.定义连接数据库函数:connect_db(db=None, cursorclass=DictCursor)6.汇总表填充必要数据7.新建各省份子 ...

  3. exshop第6天

    发现grails mongodb插件中的一个BUG并进行了提交,grails项目管理人员还进行了回复,主要是配置failOnError 后不起作用了,不过项目负责人还是确认了这个问题,估计会比较快的解 ...

  4. python全栈开发day101-认证组件、权限组件、频率组件

    1.Mixins类分析 这两个函数都在GenericAPIView下,这就是为什么必须搭配继承GenericAPIView的原因. 这两个主要是get_object()较为复杂. 2.认证组件源码分析 ...

  5. windows server 2008性能测试出现大量time_wait

    netstat -an | find "TCP" /C netstat -an | find "TIME_WAIT" /C taskkill /im mmdrv ...

  6. plink命令

    用plink远程登陆link主机执行脚本,但是无法执行sudo命令 完成后自己关闭 plink   -l  root   192.168.1.21  df -h plink.exe  -ssh  -p ...

  7. tomcat优化,java查看

    java堆空间分为  新生代 ,老年代 , 持久代 各自有各自的垃圾回收算法 eden区:新生的对象存放在这经常被回收 from  .to  存活区 在老年代,回收的频率不是很高 jdk8 就没有持久 ...

  8. 利用vcard和qrcode.js生成二维码导入联系人

    vCard是一种容许交换个人信息的数据规范,vCard数据格式的标识符是VCARD,vCard数据格式行是: 类型 [;参数]:值,具体的介绍百度都有,我们可以通过vcard来进行通讯录的保存,名片的 ...

  9. HtmlTestRunner

    1.一般生成报告时,会使用时间来作为报告名称的一部分,引入time这个第三方,使用以下方式格式化当前时间 下面运行最终结果:2019-03-29-14_29_18------>年-月-日-时-分 ...

  10. 三色抽卡游戏 博弈论nim

    你的对手太坏了!在每年的年度三色抽卡游戏锦标赛上,你的对手总是能打败你,他的秘诀是什么? 在每局三色抽卡游戏中,有n个卡组,每个卡组里所有卡片的颜色都相同,且颜色只会是红(R).绿(G).蓝(B)中的 ...