Cod sursa(job #2119502)

Utilizator Moise_AndreiMoise Andrei Moise_Andrei Data 1 februarie 2018 12:36:37
Problema Cele mai apropiate puncte din plan Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;
ifstream in("cmap.in");
ofstream out("cmap.out");
pair <int, int> v[100005];
double f(pair <int, int> &a, pair <int, int> &b)
{
    double s1 = (1.0 * (a.first - b.first)) * (1.0 * (a.first - b.first));
    double s2 = (1.0 * (a.second - b.second)) * (1.0 * (a.second - b.second));
    return sqrt(s1 + s2);
}
int main()
{
    int n;
    in >> n;
    for(int i = 1; i <= n; i++)
        in >> v[i].first >> v[i].second;
    sort(v + 1, v + n + 1);
    double mn = (1 << 30);
    for(int i = 1; i <= n; i ++)
        for(int j = i + 1; j <= n && v[j].first - v[i].first <= mn; j ++)
            mn = min(mn, f(v[i], v[j]));
    out << setprecision(10) << fixed << mn;
    return 0;
}