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,如何 ...
随机推荐
- SQLMAP注入常见用法
1.检查注入点 sqlmap -u http://www.com.tw/star_photo.php?artist_id=11 2.列数据库信息当前用户和数据库 sqlmap -u http://ww ...
- BufPay.com 个人收款接口 接入步骤
作为独立开发者产品需要收款是非常麻烦的,注册公司维护成本太高,市面上各种收款工具要么手续费太高,要么到账很慢,体验很不好. 看到 「BufPay.com 个人收款」 这个收款工具,挺有意思的.原理是监 ...
- 静态导入方法即自动拆装箱(java)
package example6;import static java.lang.System.out;import static java.util.Arrays.sort;import java. ...
- html5 video获取当前时间和视频总时间长度
html: <video id="video-active" class="video-active" width="640" hei ...
- php 遍历一个文件夹下的所有文件和子文件
php 遍历一个文件夹下的所有文件和子文件 <?php /** * 将读取到的目录以数组的形式展现出来 * @return array * opendir() 函数打开一个目录句柄,可由 clo ...
- Hive(8)-常用查询函数
一. 空字段赋值 1. 函数说明 NVL:给值为NULL的数据赋值,它的格式是NVL( value,default_value).它的功能是如果value为NULL,则NVL函数返回default_v ...
- Mac进度条卡在100%
- fiddler响应报文的headers属性详解
fiddler响应报文的headers属性详解 (1)Cache头域 1. Cache-Control 在请求报文已经说过了,用于设置缓存的属性,浏览内容不被缓存. 2. Data 生成消息的具体时间 ...
- shell之lvm
#!/bin/bash #this script for LVM echo "Initial a disk..." echo -e "\033[31mWarning: ...
- 推荐 的FPGA设计经验(2)-时钟策略优化
Optimizing Clocking Schemes Avoid using internally generated clocks (other than PLLs) wherever possi ...