Cod sursa(job #1636397)

Utilizator raduzxstefanescu radu raduzx Data 7 martie 2016 09:32:22
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <fstream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
struct punct
{
    long double x,y;
};
punct v[100005];
bool cmp(punct a,punct b)
{
    if(a.x<b.x)
        return 1;
    else
        return 0;
}
long double dist(punct a,punct b)
{
    double l;
    l=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
    return sqrt(l);
}
int main()
{
    ifstream f("cmap.in");
    ofstream g("cmap.out");
    int n,j;
    f>>n;
    int i;
    for(i=1;i<=n;i++)
    {
        f>>v[i].x>>v[i].y;
    }
    sort(v+1,v+n+1,cmp);
    long double mi,w;
    mi=dist(v[1],v[2]);
    for(i=3;i<=n;i++)
    {
        j=i-1;
        while(v[i].x-v[j].x<mi and j>=1)
        {
            w=dist(v[i],v[j]);
            if(mi>w)
                mi=w;
            j-=1;
        }
    }
    g<<fixed<<setprecision(6)<<mi;
    return 0;
}