Quoit Design

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 54667    Accepted Submission(s): 14401

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

 
 //2017-08-09
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#define mid ((l+r)>>1) using namespace std; const int N = ;
struct Point{
double x, y;
}P[N], p1[N], p2[N];
int n; bool cmp_x(Point a, Point b){
return a.x < b.x;
} bool cmp_y(Point a, Point b){
return a.y < b.y;
} double distance(Point *a, Point *b){
return sqrt((a->x - b->x)*(a->x - b->x) + (a->y - b->y)*(a->y - b->y));
} //分治,solve(l, r)表示区间[l, r]内的最近点对,solve(l, r) = min(solve(l, mid), solve(mid+1, r), 跨左右子区间的最近点对)
double solve(int l, int r){
if(l >= r)return ;
if(r - l == )return distance(&P[l], &P[r]);
if(r - l == )return min(distance(&P[l], &P[l+]), distance(&P[l+], &P[r]));
double ans = min(solve(l, mid), solve(mid+, r));
//暴力x坐标与mid的x坐标相差不超过当前最优解ans的点
int m = ;
for(int i = l; i <= r; i++){
if(fabs(P[mid].x - P[i].x) <= ans){
p1[m++] = P[i];
}
}
sort(p1, p1+m, cmp_y);
for(int i = ; i < m; i++){
for(int j = i+; j < m; j++){
if(p1[j].y - p1[i].y > ans)break;
ans = min(ans, distance(&p1[i], &p1[j]));
}
}
return ans;
} int main()
{
//freopen("dataIn.txt", "r", stdin);
while(scanf("%d", &n)!=EOF && n){
for(int i = ; i < n; i++)
scanf("%lf%lf", &P[i].x, &P[i].y);
sort(P, P+n, cmp_x);
printf("%.2lf\n", solve(, n-)/);
} return ;
}

HDU1007(最近点对)的更多相关文章

  1. Quoit Design(hdu1007)最近点对问题。模版哦!

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

  2. HDU1007最近点对(分治)

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 直接见代码吧.不过这个是N*logN*logN的 尽管如此,我怎么感觉我的比他们的还快??? #inclu ...

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

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

  4. hdu1007 平面最近点对(暴力+双线程优化)

    突发奇想,用双线程似乎可以优化一些暴力 比如说平面最近点对这个题目,把点复制成2份 一份按照x排序,一份按照y排序 然后双线程暴力处理,一份处理x,一份处理y 如果数据利用x递减来卡,那么由于双线程, ...

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

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

  6. 最近点对HDU1007

    利用二分的方法来计算,应该是说利用分治的方法吧! 刚开始感觉时间会爆 后来发现嘎嘎居然没有 ,嗨自己算错了时间: #include <iostream> #include<cstdi ...

  7. 【hdu1007】最近点对

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 分治法的经典应用,复杂度可以证明为nlognlogn #include <iostream> ...

  8. ICP算法(Iterative Closest Point迭代最近点算法)

    标签: 图像匹配ICP算法机器视觉 2015-12-01 21:09 2217人阅读 评论(0) 收藏 举报 分类: Computer Vision(27) 版权声明:本文为博主原创文章,未经博主允许 ...

  9. Quoit Design---hdu1007(最近点对问题 分治法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:给你n(2<=n<=10^6)个点的坐标,然后找到两个点使得他们之间的距离最小 ...

随机推荐

  1. Linux巩固记录(7) Hbase安装

    zookeeper安装好,并启动成功后,接下来开始安装hbase #下载hbase wget http://mirror.bit.edu.cn/apache/hbase/1.3.1/hbase-1.3 ...

  2. 【AWK】:常用总结

    单机文本数据处理,常用AWK,总结一下AWK最常用的要点,备忘备查. 1.What is AWK(1)Aho.Weinberger.Kernighan三位发明者名字首字母:(2)一个行文本处理工具: ...

  3. MySQL 5.6不删空用户的影响

    目录 MySQL 5.6不删空用户的影响 问题 分析 测试 启动mysqld时没有加上--skip-name-resolve 启动mysqld时加上--skip-name-resolve 结论 MyS ...

  4. js缓存问题,修改js后代码不生效

    问题描述 最近在上线新版本项目的时候,发现有的用户的操作还是调用的老版本JS里面的内容,这样就造成原来新的JS里面加上的限制不能限制用户的操作,从而导致用户可以重复操作. 问题产生原因 如果在用户之前 ...

  5. Python3之PrettyTable模块

    一. 简介 Python通过prettytable模块将输出内容如表格方式整齐输出,python本身并不内置,需要独立安装该第三方库. 二. 安装 方式一:pip安装 >>> pip ...

  6. [Leetcode]315.计算右侧小于当前元素的个数 (6种方法)

    链接 给定一个整数数组 nums,按要求返回一个新数组 counts.数组 counts 有该性质: counts[i] 的值是  nums[i] 右侧小于 nums[i] 的元素的数量. 示例: 输 ...

  7. POJ 2845

    #include <iostream> #include <string> #include <algorithm> #define MAXN 350 using ...

  8. spring boot 中使用swagger 来自动生成接口文档

    1.依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swa ...

  9. 没啥事用C语言写一个Trie tree玩玩,支持中英文,用g++编译通过

    #include <cstdio> #include <cstdlib> #include <vector> #define ALPHABETS 2600000 # ...

  10. office2013安装与卸载

    一.office2013卸载不干净,重新安装的时候就会报错.下面是博主卸载的步骤: 第一步:下载office官方卸载工具 ,链接:http://pan.baidu.com/s/1nvuoEYd 密码: ...