Cod sursa(job #1929690)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 17 martie 2017 22:34:10
Problema Cele mai apropiate puncte din plan Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>

#define ld long double
using namespace std;
ifstream f("cmap.in");
ofstream g("cmap.out");

const int NMax = 100001;
const ld INF = 10000000000;

struct point{
    ld x,y;
};

point a[NMax];
int n;

bool cmp(point x, point y){
    return (x.x < y.x);
}
ld dist(point a, point b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main()
{
    f >> n;
    for(int i = 1; i <= n; ++i)
        f >> a[i].x >> a[i].y;
    sort(a + 1, a + 1 + n,cmp);

    ld t = INF;

    for(int i = 1; i <= n; ++i){
        for(int j = i + 1; j <= n; ++j){
            if(dist(a[i],a[j]) > t)
                break;
            t = dist(a[i],a[j]);
        }
    }
    g << fixed << setprecision(6) << t << '\n';
    return 0;
}