Mai intai trebuie sa te autentifici.

Cod sursa(job #2074044)

Utilizator priestnoobFMI - Dan Nema priestnoob Data 24 noiembrie 2017 00:50:15
Problema Cele mai apropiate puncte din plan Scor 35
Compilator cpp Status done
Runda Arhiva educationala Marime 1.25 kb
#include <iostream>
#include <fstream>
#include <math.h>
#include <utility>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

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

#define nmax 100001
#define inf 10000000000

bool comp(pair <long,long> a, pair <long,long> b)
{
    if(a.first<b.first) return 1;
    if(a.first==b.first && a.second<b.second) return 1;
    return 0;
}

//vector <pair <long,long> > v;
pair<long, long> v[nmax];

long long d(pair<long,long> a, pair<long, long> b)
{
    return pow((a.first-b.first),2) + pow((a.second-b.second),2);
}

long long solve(int a, int b)
{
    if(a==b) return inf;
    if(b-a==1) return d(v[a],v[b]);
    int m = (a+b)/2;
    long long rez=min(solve(a,m),solve(m+1,b));
    int aux[nmax],k=1;
    for(int i=a;i<=m;++i)
        if(v[m].first-v[i].first<rez) aux[k]=i,++k;
    for(int j=1;j<=k;++j)
        for(int i=1;i<8&&((j+i)<=b);++i)
        rez=min(rez,d(v[j],v[i+j]));
    return rez;
}

int main()
{
    int n;
    pair<long,long> aux;
    f>>n;
    for(int i=1;i<=n;++i)
    {
        f>>aux.first>>aux.second;
        v[i]=aux;
    }
    sort(v+1,v+n+1,comp);
    long long rez = solve(1,n);
    g<<fixed<<setprecision(7)<<sqrt((double)rez);
}