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 ...
随机推荐
- Using Pre-Form Trigger In Oracle Forms
Pre-Form trigger in Oracle Forms fires during the form start-up, before forms navigates to the first ...
- EasyUI--初学
首先的是配置: 在WebContent下导入jQuery-EasyUI包 其次在HTML或jsp页面的<head></head>标签中,导入或引用js包 <head> ...
- ABAP 内表 详解
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 键盘unicode值对照表
A:65 B:66 C:67 D:68 E:69 F:70 G:71 H:72 I:73 J:74 K:75 L:76 M:77 N:78 O:79 P:80 Q:81 R:82 S:83 T:84 ...
- zoj 2107&&hdu 1007最近点对问题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1107 Quoit Design Time Limit: 5 Seconds ...
- placeholder在ie浏览器里不显示的问题解决
<script type="text/javascript"> if( !('placeholder' in document.createElement('input ...
- MVC中Html.Listbox的用法实例
要绑定listbox或dropdownlist前提是:必须是SelectItem类,例如: 因为Html.ListBox第二个绑定数据的参数要得类型为SelectList第一种:因为listbox可以 ...
- Android网络编程系列 一 Socket抽象层
在<Android网络编程>系列文章中,前面已经将Java的通信底层大致的描述了,在我们了解了TCP/IP通信族架构及其原理,接下来我们就开始来了解基于tcp/ip协议层的Socket抽 ...
- iOS 开发之 Xcode6 创建真机调试证书
http://jingyan.baidu.com/article/ff411625b8141312e48237a7.html 1.登录苹果开发者中心 2.登录后的界面如图所示,如果没有最上面的两个选项 ...
- Android入门:绑定本地服务
一.绑定服务介绍 前面文章中讲过一般的通过startService开启的服务,当访问者关闭时,服务仍然存在: 但是如果存在这样一种情况:访问者需要与服务进行通信,则我们需要将访问者与服务进行绑定: ...