poj3669 Meteor Shower(BFS)
我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了。。。
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<algorithm>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std; const int N = ;
const int inf = 0x3f3f3f3f;
int dir[][]={-,,,,,,,-};
int vis[N][N], g[N][N];
struct point{
int x, y;
int d;
point(int x=,int y=,int d=):x(x),y(y),d(d){}
};
int jud(int x, int y, int d){
if(x >= && x < N && y >= && y < N && !vis[x][y] && d < g[x][y])
return ;
return ;
}
int bfs(){
CLR(vis, );
queue<point>q;
point u, v;
vis[][] = ;
q.push(point(,,));
while(!q.empty()){
u = q.front(); q.pop();
for(int i = ; i < ; ++i){
v.x = u.x + dir[i][];
v.y = u.y + dir[i][];
v.d = u.d + ;
if(jud(v.x, v.y, v.d)){
if(g[v.x][v.y] == inf)//安全区域
return v.d;
vis[v.x][v.y] = ;
q.push(v);
}
}
}
return -;
}
int main(){
int m, i, x, y, t;
CLR(g,inf);
scanf("%d", &m);
for(i = ; i < m; ++i){
scanf("%d%d%d", &x, &y, &t);
g[x][y] = min(t, g[x][y]);
if(x > && t < g[x-][y])
g[x-][y] = t;
if(y > && t < g[x][y-])
g[x][y-] = t;
g[x+][y] = min(t, g[x+][y]);
g[x][y+] = min(t, g[x][y+]);
}
if(g[][] == ){printf("-1\n");return ;}
if(g[][] == inf){printf("0\n");return ;}
printf("%d\n",bfs());
return ;
}
poj3669 Meteor Shower(BFS)的更多相关文章
- POJ3669(Meteor Shower)(bfs求最短路)
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12642 Accepted: 3414 De ...
- POJ-3669 Meteor Shower(bfs)
http://poj.org/problem?id=3669 注意理解题意:有m颗行星将会落在方格中(第一象限),第i颗行星在ti时间会摧毁(xi,yi)这个点和四周相邻的点,一个人开始在原点,然后只 ...
- POJ 3669 Meteor Shower BFS求最小时间
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31358 Accepted: 8064 De ...
- poj3669 Meteor Shower(预处理+bfs)
https://vjudge.net/problem/POJ-3669 先给地图a[][]预处理每个位置被砸的最小时间.然后再bfs. 纯bfs,还被cin卡了下时间.. #include<io ...
- POJ3669 Meteor Shower
http://poj.org/problem?id=3669 类似于迷宫的一道题 但是并没有 给出迷宫具体什么样 但是题目已说在坐标轴的第一象限 然后障碍就是 流星雨所砸范围 安全位置:永远不会发生危 ...
- POJ 3669 Meteor Shower BFS 水~
http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...
- poj3669 Meteor Shower (宽度优先搜索)
Description - 题目描述 Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平面坐标系的原点放牧,打算在群星 ...
- 【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 ...
随机推荐
- sql 执行计划
SQL Server执行计划的理解 要理解执行计划,怎么也得先理解,那各种各样的名词吧.鉴于自己还不是很了解.本文打算作为只写懂的,不懂的懂了才写. 在开头要先说明,第一次看执行计划要注意,SQL S ...
- SQL函数学习(十九):CAST()函数和CONVERT()函数
19.CAST()函数和CONVERT()函数 CAST()函数可以将某种数据类型的表达式转化为另一种数据类型 CONVERT()函数 也 可以将指定的数据类型转换为另一种数据类型 19.1 CAST ...
- mysql密码忘记或者不知道,怎么办?
运行cmd: 输入mysql回车,如果成功,将出现MySQL提示符 > 连接权限数据库>use mysql; (>是本来就有的提示符,别忘了最后的分号) 修改改密码:> upd ...
- 3.27考试总结(hnoi难度)
1 duel1.1 DescriptionK·⁄¶("“uƒ¢y%¥§H5|+ (?1’m" ’m·ø?1§z<k§⁄k<⁄§lm?0,1,2...§zg ‹‰ª«mS ...
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out! 思路
C. Guess Your Way Out! time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 3----lua的数据转换及运算符
lua的基本数据类型转换 转换成字符串 tostring( ... ) 可以将布尔类型和数字类型的值转换为字符串类型的值 local num=1; print(type(num)) newNum = ...
- 阿里商业评论 | 互联网POI数据及其在营销中的应用
阿里商业评论 | 互联网POI数据及其在营销中的应用 时间 2014-11-05 10:40:50 阿里研究院 原文 http://www.aliresearch.com/index.php?m- ...
- Springmvc中 同步/异步请求参数的传递以及数据的返回
转载:http://blog.csdn.net/qh_java/article/details/44802287 注意: 这里的返回就是返回到jsp页面 **** controller接收前台数据的方 ...
- Windows_cmd_命令
1. netstat -ano 查看端口占用情况 netstat -anp // 命令来查看一下,Linux系统是否在监听 3306 这个端口号 2.
- ORACLE性能优化之SQL语句优化
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 操作环境:AIX +11g+PLSQL 包含以下内容: 1. SQL语句执行过程 2. 优化器及执行计划 3. 合 ...