Cod sursa(job #1464302)

Utilizator TeodorescuStefanEduardTeodorescu Stefan Eduard TeodorescuStefanEduard Data 22 iulie 2015 22:38:02
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include <fstream>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <iomanip>
 
using namespace std ;
 
ifstream fin ("cmap.in") ;
ofstream fout ("cmap.out") ;
 
 
struct punct
{
    long long int x , y ;
} ;
 
punct a [100001] ;
 
long long int n,i,j ;
long double d , dist=999999999999999999.0 ;
 
bool cmp ( punct x , punct y )
{
    return ( x.x < y.x ) ;
}
 
long double distances ( punct a , punct b )
{
    return sqrt((long double)(( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y )));
}
 
int main()
{
    fin >> n ;
    for ( i = 1 ; i <= n ; ++ i )
        fin >> a[i].x >> a[i].y ;
 
    sort ( a+1 , a+n+1 , cmp );
    for ( i = 1 ; i <= n-1 ; ++ i )
            for ( j = i + 1 ; j <= n && a[j].x - a[i].x < dist ; ++ j )
                  if ( abs ( a[j].y - a[i].y ) < dist )
                       {
                           d = distances ( a[i] , a[j] ) ;
                           if ( d < dist )
                              dist = d ;
                       }
 
    fout << fixed << setprecision(7) << dist ;
    return 0 ;
}