Pagini recente » Cod sursa (job #2061734) | Cod sursa (job #1376333) | Cod sursa (job #3139125) | Cod sursa (job #1405298) | Cod sursa (job #625776)
Cod sursa(job #625776)
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define PDD pair< double, double >
#define mp make_pair
#define x first
#define y second
#define NMAX 100005
#define INF 4e18
using namespace std;
PDD X[NMAX], Y[NMAX], Aux[NMAX];
int N, i, j, lg;
inline double Dist( const PDD &A, const PDD &B )
{
return sqrt( ( A.x - B.x )*( A.x - B.x ) + ( A.y - B.y )*( A.y - B.y ) );
}
inline double Sol( int St, int Dr )
{
if( Dr == St + 1 ) return INF;
else if( Dr == St + 2 )
{
if( Y[St] > Y[Dr - 1] )
swap( Y[St], Y[Dr - 1] );
return Dist( X[St], X[Dr - 1] );
}
int M = (St + Dr)>>1;
double DistMin = min( Sol( St, M ), Sol( M, Dr ) );
merge( Y + St, Y + M, Y + M, Y + Dr, Aux );
copy( Aux, Aux + ( Dr - St ), Y + St );
lg = 0;
for( i = St; i < Dr; ++i )
if( abs( X[M].x - Y[i].y ) <= DistMin )
Aux[ lg++ ] = Y[i];
for( i = 0; i < lg - 1; ++i )
for( j = i + 1; j < lg && j - i < 8; ++j )
DistMin = min( DistMin, Dist( Aux[i], Aux[j] ) );
return DistMin;
}
int main()
{
freopen("cmap.in", "r", stdin);
freopen("cmap.out", "w", stdout);
scanf("%d", &N);
for( i = 0; i < N; ++i )
scanf("%lf%lf", &X[i].x, &X[i].y);
sort( X, X + N );
for( i = 0; i < N; ++i )
Y[i] = mp( X[i].y, X[i].x );
printf("%.6lf\n", Sol( 0, N ));
return 0;
}