Pagini recente » Cod sursa (job #307860) | Cod sursa (job #1562235) | Cod sursa (job #1393779) | Cod sursa (job #1162259) | Cod sursa (job #1464302)
#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 ;
}