Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15345 Accepted Submission(s): 3814
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.
#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;
}