hd1007

#include 
#include 
#include 
using namespace std;

struct node
{
double x,y;
}point[100000];
int n;

bool hAlignLess(node p1,node p2)
{
if(p1.x != p2.x) return p1.x < p2.x;
else return p1.y < p2.y;
}

double getDist(node p1, node p2)
{
return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
}

double getMin(double a, double b)
{ 
return aa:b;
}

double solve(int l,int r)
{
    if(l == r)
       return 1000000000;
    if(l == r - 1)
       return getDist(point[l],point[r]);
    if(l == r - 2)
       return getMin(getMin(getDist(point[l],point[l+1]),getDist(point[l+1],point[l+2])),getDist(point[l],point[l+2]));
    int i,j,mid = (l+r) >> 1;
    double curmin = getMin(solve(l,mid),solve(mid+1,r));
    for(i=l;i<=r;i++)
       for(j=i+1;j<=i+5 && j<=r;j++)
       {
        curmin = getMin(curmin,getDist(point[i],point[j]));
       }
    return curmin;
}

int main() {
    int i;
    while(scanf("%d",&n)!=EOF && n){
       for(i = 0; i < n; i++){
            scanf("%lf %lf",&point[i].x,&point[i].y);
       }
       sort(point,point+n,hAlignLess);
       double ans = solve(0,n-1);
       printf("%.2lf\n",ans/2);
    }
    return 0;
}

 

你可能感兴趣的:(hd1007)