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. Chapter 19_0 位操作库

    位操作库是Lua5.2版本里添加的库,所有函数放在bit32 table里.(bit32只能针对32位整数运算) 在Lua5.3版本里,bit32库被废弃掉.不过可以使用一个外部兼容库,但是最好直接用 ...

  2. epoll完整例子

    #include <deque> #include <map> #include <vector> #include <pthread.h> #incl ...

  3. robotium如何定位控件?

    search类获取当前所有的view,然后根据类型或者文本去筛选,找到view后获取坐标,然后点击坐标.本质都是通过坐标点击.solo.clickonScreen方法,底层调用MotionEvent类 ...

  4. java中equals方法和contentEquals方法区别

    java中,String类里提供了两种字符串的比较方式(算上“==”应该是三种) String line1 = new String("0123456789"); String l ...

  5. lumen框架

    1,获取配置 app(); 说明:app()返回的是全局唯一的application对象,该对象的原型是Laravel\Lumen\Application 加载配置文件(config/app.php) ...

  6. myeclipse6.0安装svn插件

    myeclipse6.0安装svn插件 转载地址:http://www.cnblogs.com/danica/archive/2011/07/12/2104323.html myeclipse6.0安 ...

  7. SDK平台三态按钮的实现

    Windows平台提供了丰富的控件,但是在使用中我们不会使用它提供的默认风格,有时候需要对控件进行改写,让它展现出更友好的一面,这次主要是说明三态按钮的实现. 三态按钮指的是按钮在鼠标移到按钮上时显示 ...

  8. 第一百一十四节,JavaScript文档对象,DOM进阶

    JavaScript文档对象,DOM进阶 学习要点: 1.DOM类型 2.DOM扩展 3.DOM操作内容 DOM自身存在很多类型,在DOM基础课程中大部分都有所接触,比如Element类型:表示的是元 ...

  9. HDU 2212 DFS

    Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every d ...

  10. Spring Security(09)——Filter

    目录 1.1     Filter顺序 1.2     添加Filter到FilterChain 1.3     DelegatingFilterProxy 1.4     FilterChainPr ...