Cod sursa(job #1681529)

Utilizator razvandRazvan Dumitru razvand Data 9 aprilie 2016 15:47:38
Problema Cele mai apropiate puncte din plan Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <iomanip>

using namespace std;

struct pct {
    long long x;
    long long y;
};

ifstream in("cmap.in");
ofstream out("cmap.out");

long long dist;
pct v[100003];

bool cmp(pct a, pct b) {
    if(a.x != b.x)
        return a.x < b.x;
    else
        return a.y < b.y;
}

long long sm(int st, int dr) {

    //if(st >= dr)
    //    return INT_MAX;

    if(dr == st+1)
        return ((v[st].x-v[dr].x)*(v[st].x-v[dr].x) + (v[st].y-v[dr].y)*(v[st].y-v[dr].y));

    //cout << st << " " << dr << '\n';
    int mid = (st+dr)/2;
    return min(sm(st, mid), sm(mid, dr));

}

int main() {

    int n;
    in >> n;

    for(int i = 1; i <= n; i++)
        in >> v[i].x >> v[i].y;
    sort(v, v+n, cmp);

    //cout << sm(1, n);

    out << fixed << setprecision(6) << sqrt(sm(1, n));

    return 0;
}