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 ...
随机推荐
- 终止jQuery的$.ajax方法abort
最近遇到,如果用户频繁点击ajax请求,有两个问题: 1,如果连续点击了5个ajax请求,前4个其实是无效的,趁早结束节省资源. 2,更严重的问题是:最后一个发送的请求,响应未必是最后一个,有可能造成 ...
- 常用CMD命令
查看电脑最大支持多大的内存: wmic memphysical get maxcapacity 查询DNS: nslookup a.root-servers.net 路由线路: ...
- sqlserver前面加N解释
From : http://lzde360.blog.163.com/blog/static/6780720820111026112033917/ 加上 N 代表存入数据库时以 Unicode 格式存 ...
- T-SQL排名函数
提到排名函数我们首先可能想到的是order by,这个是排序,不是排名,排名需要在前面加个名次序号的,order by是没有这个功能的.还可能会想到identity(1,1),它也给了一个序号,但是不 ...
- ie8不支持transform: translateY,ie9支持不友好
transform: translateY(0); ie8 不支持这个属性 但是我觉得用css实现的效果特好 特自然 也许是我的脚本写的不够完善 呵呵 现在我希望其他 主流的浏览器应用CSS ...
- 2014 Multi-University Training Contest 4
1006 hdu4902 #include <iostream> #include<stdio.h> #include<vector> #include<qu ...
- swift语言学习之UITableView分割线左边到头的解决
此方法兼容ios 7.8.9 // 在tableView创建地方设置 if tableView!.respondsToSelector("setSeparatorInset:") ...
- linux简单配置
lsof -i lsof -i:211.判断apache查找httpd路径: ps aux | grep httpd 结果: /usr/local/apache/bin/httpd /usr/loc ...
- hibernate Criteria查询多对多(Set集合)条件筛选
PO public class UserPO implements java.io.Serializable { /** 用户唯一标识ID */ private String id; /** 状态(在 ...
- final运用于内部类访问局部变量
final运用于内部类访问局部变量 public void mRun( final String name){ new Runnable() { @Override public void run() ...