Cod sursa(job #1489025)

Utilizator tudormaximTudor Maxim tudormaxim Data 20 septembrie 2015 13:51:04
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <bits/stdc++.h>
using namespace std;
const int nmax  = 100005;
const int inf = 0x3f3f3f3f;
struct point {long long x, y;} t[nmax];
double sol;

double sqr(double x)
{
    return (x*x);
}

bool cmp(point a, point b)
{
    if (a.x==b.x) return (a.y < b.y);
    else return (a.x < b.x);
}

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

long long ok(point a, point b)
{
    if (a.x==b.x) return abs(double(b.y-a.y));
    else return abs(a.x-b.x);
}

int main()
{
    freopen("cmap.in", "r", stdin);
    freopen("cmap.out", "w", stdout);
    int i, j, n;
    scanf("%d",&n);
    for (i=1; i<=n; i++)
        scanf("%lld %lld", &t[i].x, &t[i].y);
    sort(t+1, t+n+1, cmp);
    sol=1e16;
    for (i=1; i<=n; i++)
        for (j=i+1; j<=n && ok(t[i],t[j])<sol; j++)
            if (abs(double(t[j].y-t[i].y))<sol) sol=min(sol,dist(t[j],t[i]));
    printf("%f", sol);
    fclose(stdin);
    fclose(stdout);
    return 0;
}