Quoit Design

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

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
题目大意:给n个点,求最近点对距离的一半。
按x值排序,分治法二分递归搜索,合并的时候注意一下把那些fabs(p[i].x-p[mid].x)<=ans的点找出来,这些点中可能有更小的ans,把他们按y值排序,暴力两层循环更新ans,当p[j].y-p[i].y>=ans时没必要继续了。
 #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; const int maxn=;
int N,f[maxn];
struct Point
{
double x,y;
}p[maxn]; double min(double a,double b){ return a<b?a:b;}
bool cmpx(const Point &a,const Point &b)
{
return a.x<b.x;
}
bool cmpy(const int a,const int b)
{
return p[a].y<p[b].y;
}
double dist(int a,int b)
{
return sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));
}
double BinarySearch(int l,int r)
{
if(l+==r)
{
return dist(l,r);
}
if(l+==r)
{
return min(min(dist(l,l+),dist(l+,l+)),dist(l,l+));
}
int mid=(l+r)>>;
double ans=min(BinarySearch(l,mid),BinarySearch(mid+,r));
int i,j,cnt=;
for(i=l;i<=r;i++)
{
if(fabs(p[i].x-p[mid].x)<=ans)
f[cnt++]=i;
}
sort(f,f+cnt,cmpy);
for(i=;i<cnt;i++)
{
for(j=i+;j<cnt;j++)
{
if(p[f[j]].y-p[f[i]].y>=ans) break;
ans=min(ans,dist(f[i],f[j]));
}
}
return ans;
}
int main()
{
while(scanf("%d",&N),N)
{
for(int i=;i<N;i++)
scanf("%lf %lf",&p[i].x,&p[i].y);
sort(p,p+N,cmpx);
printf("%.2lf\n",BinarySearch(,N-)/);
}
return ;
}
 

hdu 1007 Quoit Design 分治求最近点对的更多相关文章

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

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

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

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

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

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

  4. hdu 1007 Quoit Design(平面最近点对)

    题意:求平面最近点对之间的距离 解:首先可以想到枚举的方法,枚举i,枚举j算点i和点j之间的距离,时间复杂度O(n2). 如果采用分治的思想,如果我们知道左半边点对答案d1,和右半边点的答案d2,如何 ...

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

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

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

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

  7. hdu 1007 Quoit Design (最近点对问题)

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

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

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

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

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

随机推荐

  1. Linux Cache 机制探究

    http://www.penglixun.com/tech/system/linux_cache_discovery.html

  2. npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\James\package.json'

    在运行如下命令时, 遇到了问题: npm install --registry=https://registry.npm.taobao.org npm run dev 错误提示: 解决办法: 生成一个 ...

  3. Bootstrap历练实例:标签页内的下拉菜单

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  4. mariadb多源主从复制错误跳过.md

    mysql 的主从错误跳过和mariadb的多源主从复制错误跳过操作不同,请注意: 更改会话的default_master_connection变量 STOP SLAVE 'slave_account ...

  5. Node项目实战-静态资源服务器

    打开github,在github上创建新项目: Repository name: anydoor Descripotion: Tiny NodeJS Static Web server 选择:publ ...

  6. 不依赖Hibernate的万能BaseDao---模仿了Hibernate底层的原理

    今天写了个万能的BaseDao:有了这个BaseDao以后的Dao层直接继承这个BaseDao就能直接操作数据库了,增删改查,这是一个简易的Hibernate模型.写这个BaseDao的原因是最近在学 ...

  7. asp发送短信验证码 pst方式

    <script language="jscript" runat="server">  Array.prototype.get = function ...

  8. windows 2008r2+php5.6.28环境搭建详细过程

    安装IIS7 安装php 网站验证 安装IIS7 1.打开服务器管理器(开始-计算机-右键-管理-也可以打开),添加角色 直接下一步 勾选Web服务器(IIS),下一步,有个注意事项继续下一步(这里我 ...

  9. Python3学习了解日记

    # 单行注释 ''' 多行注释 ''' """ 这个也是多行注释 """ ''' 声明变量 Python 中的变量不需要声明.每个变量在使用 ...

  10. 前端之bootstrap

    一.响应式介绍 众所周知,电脑.平板.手机的屏幕是差距很大的,假如在电脑上写好了一个页面,在电脑上看起来不错,但是如果放到手机上的话,那可能就会乱的一塌糊涂,这时候怎么解决呢?以前,可以再专门为手机定 ...