Cod sursa(job #2052305)

Utilizator dan.gutuDan Gutu dan.gutu Data 30 octombrie 2017 13:35:52
Problema Cele mai apropiate puncte din plan Scor 25
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

#define inf 1e18;

struct punct
{
    int x,y;
}p[100020], p1[100020];

bool comp1(const punct &a, const punct &b)
{
    return a.x < b.x;
}

bool comp2(const punct &a, const punct &b)
{
    return a.y < b.y;
}

long long dist (punct a, punct b)
{
    return 1LL*(a.x-b.x)*(a.x-b.x) + 1LL*(a.y-b.y)*(a.y-b.y);
}

long long solve(int st, int dr)
{
    if (st >= dr)
        return inf;
    if (st+1 == dr)
    {
        return dist(p[st], p[dr]);
    }
    int mid = (st+dr)/2;
    long long sol = min(solve(st,mid), solve(mid+1,dr));
    //merge(p+st,p+mid+1,p+mid+1,p+dr+1,p1+st,comp2);
    return sol;
}

int main()
{
    ifstream cin("cmap.in");
    ofstream cout("cmap.out");
    int n;
    cin >> n;
    for (int i = 1; i<=n; i++)
        cin >> p[i].x >> p[i].y;
    sort(p, p+n, comp1);
    cout<<setprecision(6)<<fixed<<sqrt(solve(1,n));
    return 0;
}