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 ...
随机推荐
- TeeChart中 Line的Clear方法
需要注意的是,如果设置了Line.Smoothed=true; 那么调用Clear是无效的,虽然清除了曲线上的点. 但是界面上的曲线,并没有消失. 所以,在每一次Line.Clear();之前,必须确 ...
- HUD5423 Rikka with Tree(DFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5423 Rikka with Tree Time Limit: 2000/1000 MS (Java/O ...
- 表单美化-原生javascript和jQuery下拉列表(兼容IE6)
效果: 思想:用其他标签配合脚本和隐藏的input并通过传值模拟表单元素中的select <!DOCTYPE HTML> <html lang="en-US"&g ...
- [转载] Linux下高并发socket最大连接数所受的各种限制
原文: http://mp.weixin.qq.com/s?__biz=MzAwNjMxNjQzNA==&mid=207772333&idx=1&sn=cfc8aadb422f ...
- web设计经验<七>13步打造优雅的WEB字体
今天,大多数浏览器已经默认支持Web字体,日趋增多的字体特性被嵌入最新版HTML和CSS标准中,Web字体即将迎来一个趋于复杂的崭新时代.下面是一些基本的关于字体的规则,特别适用于Web字体. 原文地 ...
- awt组件中文乱码Intellij解决
-Dfile.encoding=GB18030 -Dfile.encoding=GB18030
- Linux下搭建SVN服务
SVN有几种方式进行访问,比较常见的是通过自带协议访问(svn://),配置很简单,还有一种就是http协议访问,需要结合apache服务,配置相对繁琐. 安装svn yum -y install s ...
- 【Todo】Python字符编码学习
Python中经常出现字符编码问题,在这里统一整理吧. 参考这篇文章:http://www.cnblogs.com/huxi/archive/2010/12/05/1897271.html 另外这个人 ...
- go中间的&和*
package main import "fmt" func main() { var a int = 1 var b *int = &a var c **int = &a ...
- PHP的UTF-8中文转拼音处理类(性能已优化至极致)
<?php /** * PHP 汉字转拼音 * @author Jerryli(hzjerry@gmail.com) * @version V0.20140715 * @package SPFW ...