Pagini recente » Cod sursa (job #233075) | Solutii preONI 2007, Runda 4 | Cod sursa (job #2056845) | Cod sursa (job #126037) | Cod sursa (job #655743)
Cod sursa(job #655743)
#include <fstream>
#include <cmath>
#include <algorithm>
#define PDD pair< double, double >
#define mp make_pair
#define x first
#define y second
#define NMAX 100005
#define INF 4e18
using namespace std;
ifstream f("cmap.in"); ofstream g("cmap.out");
PDD X[NMAX], Y[NMAX], Aux[NMAX];
int N, i, j;
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 );
int lg = 0;
for(int i = St; i < Dr; ++i )
if( abs( X[M].x - Y[i].y ) <= DistMin )
Aux[ lg++ ] = Y[i];
for(int i = 0; i < lg - 1; ++i )
for(int j = i + 1; j < lg && j - i < 8; ++j )
DistMin = min( DistMin, Dist( Aux[i], Aux[j] ) );
return DistMin;
}
int main()
{ f>>N;
for( i = 0; i < N; ++i ) f>>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 );
g.precision( 16 ); g<< Sol( 0, N )<<'\n';
g.close(); return 0;
}