Quoit Design

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

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
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1024 1016 3629 1044 1147 
 
 //1468MS    2288K    1378 B    G++
/* 题意;
给出n个点,求最近的两个点的距离的一般 最近点对:
要用到分治的思想做,是时间复杂度为O(nlgn),直接求会超时
最近点对问题在很多算法书和资料上都有讲到,主要思想是分治。 注意一点: 用C的 qsort排序一直TLE,表示有点无力.. */
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#define N 100005
using namespace std;
struct node{
double x,y;
}p[N];
int a[N];
int n;
double cmpx(node a,node b)
{
return a.x<b.x;
}
double cmpy(int a,int b)
{
return p[a].y<p[b].y;
}
inline double Max(double a,double b)
{
return a>b?a:b;
}
inline double Min(double a,double b)
{
return a<b?a:b;
}
inline double Dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double find(int l,int r)
{
if(l==r) return 0x7ffffff;
if(r==l+) return Dis(p[l],p[r]);
if(r==l+) return Min(Dis(p[l],p[r]),Min(Dis(p[l],p[l+]),Dis(p[l+],p[r])));
int mid=(l+r)>>;
double d=Min(find(l,mid),find(mid+,r));
int cnt=;
for(int i=l;i<=r;i++){
if(p[i].x>=p[mid].x-d && p[i].x<=p[mid].x+d)
a[cnt++]=i;
}
sort(a,a+cnt,cmpy);
for(int i=;i<cnt;i++){
for(int j=i+;j<cnt;j++){
if(p[a[j]].y-p[a[i]].y>=d) break;
d=Min(d,Dis(p[a[i]],p[a[j]]));
}
}
return d;
}
int main(void)
{
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n,cmpx);
printf("%.2lf\n",find(,n-)/);
}
return ;
}

hdu 1007 Quoit Design (最近点对问题)的更多相关文章

  1. HDU 1007 Quoit Design最近点对( 分治法)

    题意: 给出平面上的n个点,问任意点对之间的最短距离是多少? 思路: 先将所有点按照x坐标排序,用二分法将n个点一分为二个部分,递归下去直到剩下两或一个点.对于一个部分,左右部分的答案分别都知道,那么 ...

  2. HDU 1007 Quoit Design(经典最近点对问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...

  3. HDU 1007 Quoit Design【计算几何/分治/最近点对】

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

  4. hdu 1007 Quoit Design 分治求最近点对

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

  5. HDU 1007 Quoit Design(二分+浮点数精度控制)

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

  6. 杭电OJ——1007 Quoit Design(最近点对问题)

    Quoit Design Problem Description Have you ever played quoit in a playground? Quoit is a game in whic ...

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

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

  8. HDU 1007 Quoit Design(计算几何の最近点对)

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

  9. hdu 1007 Quoit Design(分治法求最近点对)

    大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...

随机推荐

  1. C/C++程序基础 (十)模板和泛型

    什么是泛型编程 基于模板,有效将算法和数据结构分离. 模板 包括类型和参数 模板函数:抽象的函数定义,代表一类同构函数.编译器在其调用位置自动完成对应模板函数的实例化. 模板类:抽象的类定义,代表更高 ...

  2. SpringBoot注入Mapper提示Could not autowire. No beans of 'xxxMapper' type found错误

    通过用Mabatis的逆向工程生成的Entity和Mapper.在Service层注入的时候一直提示Could not autowire. No beans of 'xxxMapper' type f ...

  3. 【shopex】真正可用的app开发机制

    shopex的app开发机制详解   网上流传的shopex4.8.5的app开发教程,不仅说得不明不白,而且由于版本问题,照着做根本是做不成的. 知其然,亦要知其所以然. shopex提供了的一个干 ...

  4. 【转载】C++中的static关键字的总结

    本文前半部分转自:博主chao_yu 本文后半部分转自:博主VincentCZW 静态变量作用范围在一个文件内,程序开始时分配空间,结束时释放空间,默认初始化为0,使用时可以改变其值. 静态变量或静态 ...

  5. 数据库中where与having的区别

    从整体声明角度分析: “where”是一个约束声明,在查询数据库结果返回之前对数据库的查询条件做一个约束,即返回结果之前起作用,“where”后面不能跟聚合函数: “having”是一个过滤声明,在查 ...

  6. 线程、进程、协程和GIL(三)

    上一篇文章介绍了:创建线程的两种方式.Event对象判断线程是否启动.利用信号量控制线程并发. 博客链接:线程.进程.协程和GIL(二) 这一篇来说说线程间通信的那些事儿: 一个线程向另一个线程发送数 ...

  7. python flask学习第2天 URL中两种方式传参

    新创建项目   自己写个url映射到自定义的视图函数 在url中传递参数 app.py from flask import Flask app = Flask(__name__) @app.route ...

  8. 笔记-爬虫-模拟登录github

    笔记-模拟登录github 1.      模拟登录github 1.1.    环境准备 安装/升级requests 2.20.0 pip install --upgrade requests pi ...

  9. 笔记-git-基础使用

    笔记-git-基础使用 1.      git相关概念 工作区(Working Directory): 就是在电脑里能看到的目录,init后的当前目录就是一个工作区: 版本库(Repository): ...

  10. PHP.27-TP框架商城应用实例-后台4-使用Gii生成品牌表的代码

    Gii安装[GII适用于商城项目] 将Gii文件夹复到application 是,访问http://xx.com/index.php/gii Gii规则[Gii使用规则与建表规则密切相关] 1.建表字 ...