Cod sursa(job #2074026)

Utilizator priestnoobFMI - Dan Nema priestnoob Data 23 noiembrie 2017 23:48:59
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.24 kb
#include <iostream>
#include <fstream>
#include <math.h>
#include <utility>
#include <vector>
#include <algorithm>

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)
{
    return a.first<b.first;
}

vector <pair <long,long> > v;

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

double 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;
    double rez=min(solve(a,m),solve(m+1,b));
    return rez;
    vector<int> aux;
    for(int i=a;i<=m;++i)
        if(v[m].first-v[i].first<rez) aux.push_back(i);
    for(int i=m+1;i<=b;++i)
        if(v[i].first-v[m].first<rez) aux.push_back(i);
    for(vector<int>::iterator it = aux.begin(); it != aux.end();++it)
        for(int i=*it+1;i<8+*it&&i<b;++i)
        rez=min(rez,d(v[*it],v[i]));
    return rez;
}

int main()
{
    int n;
    pair<long,long> aux;
    f>>n;
    for(int i=0;i<n;++i)
    {
        f>>aux.first>>aux.second;
        v.push_back(aux);
    }
    sort(v.begin(),v.end(),comp);
    g<<solve(1,n);
}