Problem Description

Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.
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.

Input

The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0.

Output

For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.

Sample Input

2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0

Sample Output

0.71
0.00
0.75

Author

CHEN, Yue

Source

ZJCPC2004

Recommend

JGShining

大意:

平面中有n个点,求要使一个固定半径的圆一次只能包围一个点的最大半径

即为求点集中的最近点对

思路:

采用了算法导论33.4节中介绍的分治法求平面最近点对,时间复杂度为:O(nlogn)

代码:

//平面最近点对,使用分治法
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
const double eps = 1e-6;
const int MAXN = 100010;
const double INF = 1e20;
struct Point
{
double x, y;
};
double dist(Point a, Point b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
Point p[MAXN];
Point tmpt[MAXN];
bool cmpxy(Point a, Point b)//排序时的比较函数
{
if (a.x != b.x)return a.x < b.x;
else return a.y < b.y;
}
bool cmpy(Point a, Point b)//按照y值排序
{
return a.y < b.y;
}
double Closest_Pair(int left, int right)
{
double d = INF; if (left == right)return d;
if (left + 1 == right)
return dist(p[left], p[right]);//递归边界 int mid = (left + right) / 2; double d1 = Closest_Pair(left, mid);//分治求两个点集合的最近点对
double d2 = Closest_Pair(mid + 1, right); d = min(d1, d2);
int k = 0;
for (int i = left; i <= right; i++)
{
if (fabs(p[mid].x - p[i].x) <= d)
tmpt[k++] = p[i];
} //tmpt为与中线距离小于等于d的点的集合
sort(tmpt, tmpt + k, cmpy);
for (int i = 0; i < k; i++)
{
for (int j = i + 1; j < k && tmpt[j].y - tmpt[i].y < d; j++)
{
d = min(d, dist(tmpt[i], tmpt[j]));
}
}//合并分治结果
return d;
}
int main()
{
int n;
while (scanf("%d", &n) == 1 && n)
{
for (int i = 0; i < n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y);
sort(p, p + n, cmpxy);//对p进行预排序
printf("%.2lf\n", Closest_Pair(0, n - 1) / 2);
}
return 0;
}

HDU1007--Quoit Design(平面最近点对)的更多相关文章

  1. HDU-1007 Quoit Design 平面最近点对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 简单裸题,测测模板,G++速度快了不少,应该是编译的时候对比C++优化了不少.. //STATU ...

  2. HDU1007 Quoit Design掷环游戏

    Quoit Design 看懂题意以后发现就是找平面最近点对间距离除以2. 平面上最近点对是经典的分治,我的解析 直接上代码 #include<bits/stdc++.h> using n ...

  3. Quoit Design(最近点对+分治)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...

  4. HDU1007 Quoit Design 【分治】

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. (hdu1007)Quoit Design,求最近点对

    Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...

  6. HDU 1007 Quoit Design 平面内最近点对

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...

  7. HDOJ-1007 Quoit Design(最近点对问题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 给出n个玩具(抽象为点)的坐标 求套圈的半径 要求最多只能套到一个玩具 实际就是要求最近的两个坐标的距离 ...

  8. 【HDOJ】P1007 Quoit Design (最近点对)

    题目意思很简单,意思就是求一个图上最近点对. 具体思想就是二分法,这里就不做介绍,相信大家都会明白的,在这里我说明一下如何进行拼合. 具体证明一下为什么只需要检查6个点 首先,假设当前左侧和右侧的最小 ...

  9. HDU1007.Quoit Design

    -- 点我 -- 题目大意 :给你一堆点,求一个最小圆能够覆盖两个点的半径(最近两点距离的一半): 最多100000个点,暴力即O(n^2)会超时,考虑二分,先求左边最短距离dl,右边dr, 和一个点 ...

  10. HDU 1007 Quoit Design | 平面分治

    暂鸽 #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #d ...

随机推荐

  1. web.confgi转换,web发布时发布配置(debug/release)生成不同的配置文件

    在web.config下有两个config文件,分比为:web.debug.config和web.replease.config文件,打开之后可以看到demo,根据demo修改后即可在发布时根据选择的 ...

  2. python setup.py install 报错ImportError: No module named setuptools

    学习光荣之路python课程时,使用python setup.py install安装其他模块时,第一次安装某模块成功了.安装另一模块却报错ImportError: No module named s ...

  3. mongodb (一)

    #mongodb安装(3.4.0) #下载安装包,解压 mkdir /data/mongodb cd /data/mongodb mkdir log conf data bin vim conf/mo ...

  4. webpack+React.js

    Webpack是目前基于React和Redux开发的应用的主要打包工具.我想使用Angular 2或其他框架开发的应用也有很多在使用Webpack. 当我第一次看到Webpack的配置文件时,它看起来 ...

  5. python学习之glob模块

    如何批量获取文件路径 import glob import os def image_proc(): for files in glob.glob('/home/xxx/filename/*.png' ...

  6. perl Mail::Sender模块发送邮件

    #!/usr/bin/perl -w use strict; use Mail::Sender; ; ){ my $sender = Mail::Sender->new({ smtp => ...

  7. UML中的类间的关系

    1.泛化(Generalization) 指的是子类与父类之间的继承关系,空心三角+实线,箭头指向父类   eg:Father类为Son类的父类     2.依赖(Dependency) 没关系 &g ...

  8. java中多态的使用

    一.动手动脑 public class ParentChildTest { public static void main(String[] args) { Parent parent=new Par ...

  9. 8VC Venture Cup 2017 - Elimination Round

    传送门:http://codeforces.com/contest/755 A题题意是给你一个数字n,让你找到一个数字m,使得n*m+1为合数,范围比较小,直接线性筛出1e6的质数,然后暴力枚举一下就 ...

  10. Paint on a Wall

    Paint on a Wall 题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4012 搜索+状态压缩 这题刚开始以为是dp(之前写过墙是一 ...