Cod sursa(job #972172)

Utilizator BitOneSAlexandru BitOne Data 11 iulie 2013 10:35:19
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <cmath>
#include <vector>
#include <limits>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <algorithm>

namespace std
{
	inline istream& operator>>(istream& in, pair<int, int>& x)
	{
		in >> x.first >> x.second;
		return in;
	}
}

using namespace std;
typedef pair<int, int> point;
typedef long long int lld;

vector<point> P;

inline lld dist(const point& x, const point& y) 
{
	return 1LL * (x.first - y.first) * (x.first - y.first) +
	       1LL * (x.second - y.second) * (x.second - y.second);
}

int main()
{
	int N;
	lld d = numeric_limits<lld>::max();
	ifstream in("cmap.in");
	ofstream out("cmap.out");
	
	in >> N;
	copy(istream_iterator<point>(in), istream_iterator<point>(), back_inserter(P));
	
	sort(P.begin(), P.end());
	for(int i = 0; i < N; ++i)
	{
		for(int j = i + 1; j < N; ++j)
		{
			if( 1LL * (P[j].first - P[i].first) * (P[j].first - P[i].first) > d) break;
			d = min(d, dist(P[j], P[i]));
		}
	}
	
	out << setprecision(6) << fixed << sqrt(d) << '\n';	
}