Cod sursa(job #717617)

Utilizator algotrollNume Fals algotroll Data 20 martie 2012 08:32:53
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.18 kb
#include<cstdio>
#include<cmath>
#include<set>
#include<vector>
#include<algorithm>
#define INF 100000000000
using namespace std;

struct point
{
    int x,y;
};
struct lower_y
{
    bool operator() (point A, point B)
    {
        return A.y<B.y;
    }
};
bool lower_x (point A, point B)
{
    return A.x<B.x;
}
double dist(point A, point B)
{
    return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));
}

int main()
{
    freopen("cmap.in","r",stdin);
    freopen("cmap.out","w",stdout);
    int nP; scanf("%d",&nP);
    vector<point> sweep;
    for (int i=1;i<=nP;i++)
    {
        point tmp;
        scanf("%d %d",&tmp.x,&tmp.y);
        sweep.push_back(tmp);
    }
    sort(sweep.begin(),sweep.end(),lower_x);
    //
    double min_d=INF;
    set<point,lower_y> setEval;
    for (int i=0; i<sweep.size(); i++)
    {
        point cur = sweep.at(i);
        for (std::set<point>::iterator it=setEval.begin();it!=setEval.end();it++)
            if (cur.x-(*it).x >= min_d) setEval.erase(it--);
            else
            if (dist(cur, *it)<min_d) min_d=dist(cur, *it);
        setEval.insert(cur);
    }
    printf("%lf", min_d);
    return 0;

}