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 ;
}
 

最新文章

  1. ios 开发之单例模式
  2. Find All Numbers Disappeared in an Array
  3. node.js学习笔记(二)
  4. Linq 操作基础
  5. 【POJ】2296 Map Labeler
  6. c++用双向链表实现模板栈
  7. Java 集合系列15之 Set架构
  8. UML元素分析
  9. [iOS基础控件 - 6.10.4] 项目启动原理 项目中的文件
  10. 线性代数(矩阵乘法):POJ 3233 Matrix Power Series
  11. vim编译安装+lua模块
  12. 使用mescroll来实现移动端页面上拉刷新, 下拉加载更多功能
  13. java操作elasticsearch实现批量添加数据(bulk)
  14. day 74ajax
  15. Docker Compose部署 nginx代理Tomcat集群
  16. BZOJ 1001: [BeiJing2006]狼抓兔子(s-t平面图+最短路求最小割)
  17. JavaScript学习(二)——深入学习js对象的原型与继承
  18. 2017-2018-1 20155308&amp;20155321&amp;20155330《信息安全技术》实验三——数字证书应用1
  19. Word TOC域的使用说明
  20. HBase-MR

热门文章

  1. Virt-install用法:
  2. rem和em的区别
  3. [LUOGU] P3952 时间复杂度
  4. 在VMware上安装centos7
  5. 二分查找、upper_bound、lower_bound
  6. graph-basic
  7. hdu 6318
  8. Python属性描述符(一)
  9. mysql PacketTooBigException 的处理方式
  10. java web开发基础实例(javabean+jsp+servlet+jdbc)