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. ssh连接卡在【To escape to local shell, press 'Ctrl+Alt+]'.】的解决方法

    一.现象 1.使用xshell连接远程主机的时候一直卡在To escape to local shell, press 'Ctrl+Alt+]'.,要等很久才能连上: Connecting to 19 ...

  2. day 39 jq 学习入门2

    ---恢复内容开始--- 前情提要: jq 是用来降低js 的工作的一个组件 一:利用jq 实现动画效果 <!DOCTYPE html> <html lang="en&qu ...

  3. Build OpenJdk

    1  ,下载源代码  nuget 2,说明文档 http://hg.openjdk.java.net/jdk8/jdk8/raw-file/tip/README-builds.html 2,安装 Cy ...

  4. Ubuntu 14.04TLS和CentOS-6(64bit)上安装Nginx

    Ubuntu 14.04上安装Nginx [参考地址]https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on- ...

  5. 关于oracle RAC心跳线采用直连 还是交换机连接的建议

    关于oracle RAC心跳线的连接方式,各个论坛,包括网上文章的说法是:官方说是不建议直连,建议采用交换机连接的方式!PS:但是,一直没有找到官方文档的出处,有知道的兄弟,烦请评论区提供下地址!!! ...

  6. mysql-定时对表分区

    1, 分区 具体可见: http://blog.csdn.net/open_data/article/details/46893331 1, 分区类型: RANGE分区:基于属于一个给定连续区间的列值 ...

  7. python学习: 优秀Python学习资源收集汇总--转

    Python是一种面向对象.直译式计算机程序设计语言.它的语法简捷和清晰,尽量使用无异义的英语单词,与其它大多数程序设计语言使用大括号不一样,它使用縮进来定义语句块.与Scheme.Ruby.Perl ...

  8. 自我总结 (三) --(Java Web学习)

    自我完善的过程就是在不断的自我总结不断的改进. 在前的近半个月里,我们经过了考试,也开始了java web的项目. 先看看这次的考试.考完之后我就觉得有点不对劲的,结果 结果真的是一塌糊涂.上周五的时 ...

  9. Redis发布订阅机制

    1. 什么是Redis Redis是一个开源的内存数据库,它以键值对的形式存储数据.由于数据存储在内存中,因此Redis的速度很快,但是每次重启Redis服务时,其中的数据也会丢失,因此,Redis也 ...

  10. 阿里巴巴java手册示例

    package com.led.daorumysql; /** * @Description:alibaba java development manual * @author 86157 * */ ...