Cod sursa(job #1984963)

Utilizator Y.MalmsteenB.P.M. Y.Malmsteen Data 26 mai 2017 17:03:03
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iomanip>
#include <fstream>
#include<algorithm>
#include<cmath>

using namespace std;

struct punct
{
    int x, y;
};

punct P[100001];
int N;

ifstream f("cmap.in");
ofstream g("cmap.out");

bool comp(const punct &A, const punct &B)
{
    return A.x < B.x;
}

long long dist2(const punct &A, const punct &B)
{
    long long dx = A.x - B.x;
    long long dy = A.y - B.y;
    return dx * dx + dy * dy;
}

double solutie()
{
    long long dmin = 0x7FFFFFFFFFFFFFFFLL;
    for(int i = 1; i <= N; i++)
        for(int j = i + 1; j <= i + 7 && j <= N; j++)
        {
            long long d = dist2(P[i], P[j]);
            if(d < dmin) dmin = d;
        }
    return sqrt(dmin);
}

int main()
{
    f >> N;
    for(int i = 1; i <= N; i++)
        f >> P[i].x >> P[i].y;
    sort(P + 1, P + N + 1, comp);
    g << fixed << setprecision(6) << solutie();
    return 0;
}