Cod sursa(job #980666)

Utilizator FlameingoAiordachioaei Marius Flameingo Data 5 august 2013 13:39:38
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <cstdio>
#include <algorithm>
#include <cmath>
#define x first
#define y second
using namespace std;

typedef pair <int, int> point;
const int NMAX = 100003;

point P[NMAX];

long long square_distance (const point &a, const point &b) {

    return (b.x - a.x) * 1LL * (b.x - a.x) + (b.y - a.y) * 1LL * (b.y - a.y);

}

int main () {

    freopen ("cmap.in", "r", stdin);
    freopen ("cmap.out", "w", stdout);
    long long p, q;
    int N, i, j;
    scanf ("%d", &N);
    for (i = 1; i <= N; ++i)
        scanf ("%d%d", &P[i].x, &P[i].y);
    sort (P + 1, P + N + 1);
    q = square_distance (P[1], P[N]);
    for (i = 1; i < N; ++i)
        for (j = i + 1; j <= N; ++j) {
            p = square_distance (P[i], P[j]);
            if (1LL * (P[i].x - P[j].x) * (P[i].x - P[j].x) > q)
                break;
            if (p < q)
                q = p;

    }
    printf ("%.6lf", sqrt (q));

}