Cod sursa(job #1197512)

Utilizator alex_bucevschiBucevschi Alexandru alex_bucevschi Data 12 iunie 2014 12:37:59
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <cstdio>
#include <algorithm>
#include <cmath>
#define N 100010
using namespace std;
struct punct
{
    double x,y;
}P[N];
double sol=2000000010.0;
int i,j,n;
double dist(punct a,punct b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(punct a,punct b)
{
    if(a.x==b.x)
        return a.y<b.y;
    return a.x<b.x;
}
int main()
{
    freopen("cmap.in","r",stdin);
    freopen("cmap.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%lf%lf",&P[i].x,&P[i].y);
    sort(P+1,P+n+1,cmp);
    for(i=1;i<=n;i++)
        for(j=i+1;j<=i+7&&j<=n;j++)
            sol=min(sol,dist(P[i],P[j]));
    printf("%.6lf",sol);
    return 0;
}