Cod sursa(job #2121461)

Utilizator HumikoPostu Alexandru Humiko Data 3 februarie 2018 18:27:41
Problema Cele mai apropiate puncte din plan Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>
#define Nmax 100005
#define valmax 1000000000

using namespace std;

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

pair <long double, long double> v[Nmax];
int n;
long double ans = valmax;

long double distanta (pair <long double, long double> a, pair <long double, long double> b)
{
    long double d1 = (a.first-b.first)*(a.first-b.first);
    long double d2 = (a.second-b.second)*(a.second-b.second);
    return sqrt(d1+d2);
}

void solve ()
{
    for ( int i = 1; i < n; ++i )
        for ( int j = i+1; j <= n && (v[j].first-v[i].first < ans ); ++j )
            ans = min(ans, distanta(v[i], v[j]));
    fout<<setprecision(6)<<fixed<<ans;
}

void read()
{
    fin>>n;
    for ( int i = 1; i <= n; ++i )
        fin>>v[i].first>>v[i].second;
    sort(v+1, v+n+1);
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    read(); solve();
}