Cod sursa(job #1684021)

Utilizator DrumeaVDrumea Vasile DrumeaV Data 10 aprilie 2016 18:45:39
Problema Cele mai apropiate puncte din plan Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define pdd pair< double, double >
#define x first
#define y second

using namespace std;

ifstream fi("cmap.in");
ofstream fo("cmap.out");

const int Mn = 1e5 + 6;

int n;
double ans;
pdd ar[Mn];

bool comp(pdd a,pdd b)
{
    if (a.x != b.x)
       return a.x < b.x;

    return a.y < b.y;
}

double dist(pdd a,pdd b)
{
    return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
}

int main()
{
    fi >> n;
    for (int i = 1; i <= n; i++)
        fi >> ar[i].x >> ar[i].y;

    sort(ar + 1, ar + 1 + n);
    ans = dist(ar[1], ar[2]);
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
        {
            double d1 = dist(ar[i], ar[j]);
            if (d1 > ans)
               break;

            ans = min(ans, d1);
        }

    fo << setprecision(18) << ans << endl;
}