HDU 1007 Quoit Design(计算几何の最近点对)
In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.
Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.
题目大意:输出最近点对的距离的一半
思路:分治法,先按X轴排序。然后两边分治算最近距离,设为res,然后按y轴合并,只提取出离中间的点的x的距离不超过res的点,采用7点比较法。
代码(1687MS):
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL; struct Point {
double x, y;
Point() {}
Point(double x, double y): x(x), y(y) {}
void read() {
scanf("%lf%lf", &x, &y);
}
double length() {
return sqrt(x * x + y * y);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
}; double dist(const Point &a, const Point &b) {
return (a - b).length();
} bool x_cmp(const Point &a, const Point &b) {
return a.x < b.x;
} bool y_cmp(const Point &a, const Point &b) {
return a.y < b.y;
} const int MAXN = ; Point p[MAXN];
double ans;
int n; double closest_pair(Point *p, int n) {
if(n <= ) return 1e100;
int mid = n / ;
double x = p[mid].x;
double res = min(closest_pair(p, mid), closest_pair(p + mid, n - mid));
inplace_merge(p, p + mid, p + n, y_cmp);
vector<Point> q;
for(int i = ; i < n; ++i) {
if(fabs(p[i].x - x) >= res) continue;
for(vector<Point>::reverse_iterator it = q.rbegin(); it != q.rend(); ++it) {
if(p[i].y - it->y >= res) break;
res = min(res, dist(p[i], *it));
}
q.push_back(p[i]);
}
return res;
} int main() {
while(scanf("%d", &n) != EOF && n) {
for(int i = ; i < n; ++i) p[i].read();
sort(p, p + n, x_cmp);
printf("%.2f\n", closest_pair(p, n) / );
}
}
HDU 1007 Quoit Design(计算几何の最近点对)的更多相关文章
- HDU 1007 Quoit Design(经典最近点对问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- HDU 1007 Quoit Design【计算几何/分治/最近点对】
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1007 Quoit Design (最近点对问题)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1007 Quoit Design 分治求最近点对
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 1007 Quoit Design 平面内最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...
- hdu 1007 Quoit Design(分治法求最近点对)
大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...
- hdu 1007 Quoit Design (经典分治 求最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
- hdu 1007 Quoit Design(平面最近点对)
题意:求平面最近点对之间的距离 解:首先可以想到枚举的方法,枚举i,枚举j算点i和点j之间的距离,时间复杂度O(n2). 如果采用分治的思想,如果我们知道左半边点对答案d1,和右半边点的答案d2,如何 ...
随机推荐
- 执行SQL查询导致磁盘耗尽故障演示
a fellow in IMG wechat group 2 met an error about running out of disk space when using MySQL ...
- 能够还原jQuery1.8的toggle的功能的插件
下面这个jQuery插件能够还原1.8的toggle的功能,如果你需要,可以直接把下面这段代码拷贝到你的jQuery里面,然后跟平时一样使用toggle的功能即可. //toggle plugin f ...
- oracle 用户尝试登录失败锁定策略及修改
-- 修改密码的有效期策略, 永不过期SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;Profile altered ...
- Java学习笔记二十一:Java面向对象的三大特性之继承
Java面向对象的三大特性之继承 一:继承的概念: 继承是java面向对象编程技术的一块基石,因为它允许创建分等级层次的类. 继承就是子类继承父类的特征和行为,使得子类对象(实例)具有父类的实例域和方 ...
- c. 求阶乘和的方法(N的值不能太大)初学者
#include <stdio.h> int main() { int n,i; int a=1; //a设置为一个数的阶乘 int b; // b 设置为阶乘的和 for(i ...
- 19-21Consent Page页实现
1-在授权服务端建立相应的显示ViewModel namespace MvcCookieAuthSample.Models { public class ConsentViewModel { publ ...
- 为什么我要放弃javaScript数据结构与算法(第六章)—— 集合
前面已经学习了数组(列表).栈.队列和链表等顺序数据结构.这一章,我们要学习集合,这是一种不允许值重复的顺序数据结构. 本章可以学习到,如何添加和移除值,如何搜索值是否存在,也可以学习如何进行并集.交 ...
- 从官网下载centos
今天想从官网下载6.5版本的CentOS,结果找了好一会儿才找到,赶紧记录下来,以备以后查询. 第一步在百度搜索centos,点击"Download CentOS",如下图所示. ...
- P2351 [SDOi2012]吊灯
P2351 [SDOi2012]吊灯 https://www.luogu.org/problemnew/show/P2351 题意: 一棵树,能否全部分成大小为x的联通块. 分析: 显然x是n ...
- 初识java atomic
2018-8-19 昨天看到java.util.concurrent.atomic相关的文章,之前有过留意但并未去了解,正好有空学习一下.本人理解atomic包是concurrent子包,当是为并发所 ...