Cod sursa(job #969890)

Utilizator mitrutstrutMitrea Andrei Ionut mitrutstrut Data 5 iulie 2013 16:53:50
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
     
    ifstream fin("cmap.in");
    ofstream fout("cmap.out");
 
    int n;
    fin >> n;
 
    vector <pair<double, double> > p(n);
 
    for(int i = 0; i < n; ++i)
        fin >> p[i].first >> p[i].second;
     
    sort(p.begin(), p.end());
     
    double d = 1e50;
 
    auto getDist = [](pair<double, double> A, pair<double, double> B) {
        return sqrt((A.first - B.first) * (A.first - B.first) + (A.second - B.second) * (A.second - B.second));
    };
 
    for(int i = 0; i < n; ++i)
        for(int j = i + 1; j < n; ++j) {
            if(p[j].first - p[i].first > d)
                break;
            d = min(d, getDist(p[i], p[j]));
        }
 
    fout.setf(ios::fixed, ios::floatfield);
     
    fout.precision(8);
 
    fout << d << "\n";
    return 0;
}