Cod sursa(job #1674179)

Utilizator CrystyAngelDinu Cristian CrystyAngel Data 4 aprilie 2016 14:32:24
Problema Cele mai apropiate puncte din plan Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.38 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
struct nod
{
    long long x,y;
};
int n;
inline bool compare(nod a,nod b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;
}
nod v[100010];
double dist(int s,int d)
{
    if(d-s>3)
    {
        double mn=min(dist(s,(s+d)/2),dist((s+d)/2,d));
        int k=0,ls,ld,i;
        double c=(v[(s+d)/2].x+v[(s+d)/2-1].x)/2;
        ls=(s+d)/2-1;
        while(c-v[ls].x<=mn && ls>-1)
            --ls;
        ld=(s+d)/2;
        while(v[ld].x-c<=mn && ld<n)
            ++ld;
        int j;
        double x;
        for(i=ls;i<ld-1;++i)
        for(j=i+1;j<i+8 && j<ld;++j)
        {
            x= sqrt(( v[j].x - v[i].x ) * ( v[j].x - v[i].x ) + ( v[j].y - v[i].y ) * ( v[j].y - v[i].y ));
            mn=min(mn,x);
        }
        return mn;
    }
    else
    {
        double mn=1e9;
        int i,j;
        for(i=s;i<d-1;++i)
            for(j=i+1;j<d;++j)
            mn=min(mn,sqrt(( v[i].x - v[j].x ) * ( v[i].x - v[j].x ) + ( v[i].y - v[j].y ) * ( v[i].y - v[j].y ) ) );
        return mn;
    }
}
int main()
{
    freopen("cmap.in","r",stdin);
    freopen("cmap.out","w",stdout);
    int i;
    scanf("%d",&n);
    for(i=0;i<n;++i)
        scanf("%lld%lld",&v[i].x,&v[i].y);
    sort(v,v+n,compare);
    double x=(dist(0,n));
    printf("%lf",x);
}