Cod sursa(job #2117901)

Utilizator LucaSeriSeritan Luca LucaSeri Data 29 ianuarie 2018 19:27:24
Problema Cele mai apropiate puncte din plan Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <fstream>
#include <iomanip>
#include <cmath>
#include <algorithm>

using namespace std;

const int MAXN = 1e5 + 10;

struct point{int x, y;};

double dist(point a, point b){
    return sqrt(1.0*(a.x - b.x) * (a.x - b.x) + 1.0*(a.y - b.y) * (a.y - b.y));
}

point v[MAXN];

inline bool cmp(point a, point b){if(a.x == b.x) return a.y < b.y; return a.x < b.x;}

int main(){
    ifstream f("cmap.in");
    ofstream g("cmap.out");


    int n;
    f >> n;
    for(register int i = 0; i < n; ++i){
        f >> v[i].x >> v[i].y;
    }

    sort(v, v + n, cmp);
    double best = dist(v[0], v[1]);

    for(register int i = 0; i < n; ++i){
        for(register int j = i + 1; j < n; ++j){
            if(v[j].x - v[i].x > best) break;
            best = min(best, dist(v[i], v[j]));
        }
    }

    g << setprecision(10) << fixed << best;
    return 0;
}