Cod sursa(job #1470092)

Utilizator cojocarugabiReality cojocarugabi Data 10 august 2015 13:23:43
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
# include <bits/stdc++.h>
using namespace std;
ifstream fi("cmap.in");
ofstream fo("cmap.out");
# define ll long long
struct pii
{
    int x,y;
};
bool operator < (pii a,pii b)
{
    return (a.x == b.x ? a.y < b.y : a.x < b.x);
}
pii s[100005];
ll ans = (1LL << 62);
void update(pii a,pii b)
{
    ans = min(ans,((ll)(a.x - b.x)) * (a.x - b.x) + ((ll)(a.y - b.y)) * (a.y - b.y));
}
int main(void)
{
    int n;
    fi>>n;
    for (int i = 1;i <= n;++i) fi>>s[i].x>>s[i].y;
    sort(s+1,s+1+n);
    for (int i = 1;i <= n;++i)
        for (int j = i + 1;j <= n && abs(s[i].x - s[j].x) < ans;++j)
            if (((ll)(s[i].y - s[j].x) * (s[i].y - s[j].x)) < ans)
                update(s[i],s[j]);
    return fo << fixed << setprecision(6) << (long double)(sqrt(ans)) << '\n',0;
}