Cod sursa(job #1908366)

Utilizator medicinedoctoralexandru medicinedoctor Data 7 martie 2017 01:08:11
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define x first
#define y second

using namespace std;

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

vector <pair<int, int> > a;

void read()
{
    int n, x, y;
    cin >> n;
    a.resize(n);

    for (int i = 0; i < a.size(); i++)
        cin >> a[i].x >> a[i].y;
}

bool f(pair<long long, long long> x, pair<long long, long long> y)
{
    return x.x < y.x;
}

double dist(pair<long long, long long> x, pair<long long, long long> y)
{
    return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));
}

double solve()
{
    sort(a.begin(), a.end(), f);

    double d = dist(a[0], a[1]);

    for (int i = 0; i < a.size(); i++)
        for (int j = i + 1; a[j].x - a[i].x < d && j < a.size(); j++)
            d = min(d, dist(a[i], a[j]));

    return d;
}

int main()
{
    read();

    cout << fixed << setprecision(10) << solve() ;

    return 0;
}