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 21_2 模式匹配函数

    基础函数比较简单,就是几个普通的函数string.byte.string.char.string.rep.string.sub.string.format还有大小写转换函数upper和lower. 接 ...

  2. django模板 实现奇偶分行

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. JS定时器设置、快速取消

    1.首先定义自己的方法 function test() { alert("开始"); } 2.在定时器中使用 setInterval("test()",1000 ...

  4. abap 一些小知识点的总结

    创建包含结构或表的内表: DATA: BEGIN OF it_tab.     INCLUDE TYPE/STRUCTURE name.       name:结构名或者表名 DATA: num TY ...

  5. Oracle SQL自带函数整理

    数字函数 abs(n):用于返回数字n的绝对值 ceil(n):返回大于等于数字n的最小整数 floor(n):返回小于等于数字n的最大整数 mod(m,n):返回m/n数字相除后的余数,如果n=0, ...

  6. HTML,JS禁止鼠标右键、禁止全选、复制、粘贴的方法

    禁止鼠标右键.禁止全选.复制.粘贴: oncontextmenu事件禁用右键菜单: js代码: document.oncontextmenu = function(){ event.returnVal ...

  7. 万恶的tileMap

    先吐槽下.. 本来,我们准备用tileMap来做地图的,但发现一个问题,就是tileMap层中不能添加cc.Sprite,这导致了tileMap只适合做2D平面没有遮挡的游戏,并且主角是不能有效率的进 ...

  8. 转发一个javascript的编码规范

    google出品:http://chajn.org/jsguide/javascriptguide.html

  9. jfinal获取服务器的IP和端口

    String serverIp = getRequest().getServerName(); Integer serverPort = getRequest().getServerPort();

  10. vsphere安装虚拟机

    新建虚拟机完成后,启动虚拟机,打开启动虚拟机控制台,选择CD/DVD驱动器 选择iso镜像,可以是本地或存储中心的iso,选择后点击虚拟机--客户机--发送Ctrl+Alt+Del,接下来就是正常的操 ...