hdu 1007 Quoit Design

Quoit Design

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


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
 
//参考了下算法导论和网上一代码、终于写出了这题,1968Ms过了
//应该算比较慢了、不过体会了下分治的思想,分治递归,感觉是神奇的东西
//特别是数组的转换
//网上说这题只要按x,y排序、然后枚举后面3个点就可以过
//试了下、真的就过了、、呵呵、不过这样就没意思了
//仰慕那些500Ms以内的,居然还有100ms的、、费解、、

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cmath>
#define eps 1e-8
#define N 100002
using namespace std;
struct XX
{
    double x,y;
    bool operator<(const XX&a)const
    {
        return x<a.x;
    }
};
struct YY
{
    double x,y;
    int id;
    bool operator<(const YY&a)const
    {
        return y<a.y;
    }
};
double dis(double &x1,double &y1,double x2,double &y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
XX X[N];
YY Y[N];
YY tp[N];
void Merge(YY *Y,YY *tp,int l,int m,int r)
{
    int k=l,i=m+1;
    while(l<=m||i<=r)
    {
        if(l>m||i<=r&&tp[i].y<=tp[l].y)
          Y[k++]=tp[i++];
        else
          Y[k++]=tp[l++];
    }
}
double mg(XX *X,YY *Y,YY *tp,int l,int r)
{
     if(r<=l+2)
     {
         double Min=100000000000;
         for(int i=l;i<r;i++)
           for(int j=i+1;j<=r;j++)
            Min=min(Min,dis(X[i].x,X[i].y,X[j].x,X[j].y));
         return Min;
     }
     int m=(l+r)>>1;
     int i,j,k;
     for(i=l,j=l,k=m+1;i<=r;i++)
     {
         if(Y[i].id<=m)
          tp[j++]=Y[i];
        else
          tp[k++]=Y[i];
     }
     double m1=mg(X,tp,Y,l,m);
     double m2=mg(X,tp,Y,m+1,r);
     m1=min(m1,m2);
     Merge(Y,tp,l,m,r);
     for(i=l,k=l-1;i<=r;i++)
     {
         if(fabs(Y[i].x-Y[m].x)<m1)
            tp[++k]=Y[i];
     }
    for(i=l;i<k;i++)
      for(j=1;j<=7;j++)
           if(i+j<=k)
           {
               m1=min(m1,dis(tp[i].x,tp[i].y,tp[i+j].x,tp[i+j].y));

           }
    return m1;
}
int main()
{
    int n;
    int i;
    while(scanf("%d",&n),n)
    {
        for(i=0;i<n;i++)
         scanf("%lf%lf",&X[i].x,&X[i].y);
       sort(X,X+n);
       for(i=0;i<n;i++)
        {
            Y[i].x=X[i].x;
            Y[i].y=X[i].y;
            Y[i].id=i;
        }
        sort(Y,Y+n);
        printf("%.2lf\n",mg(X,Y,tp,0,n-1)/2);
    }
    return 0;
}

posted on 2012-08-02 19:03  江财小子  阅读(1415)  评论(0编辑  收藏  举报