Cod sursa(job #2089093)

Utilizator fulger13Pomirleanu Sebastian fulger13 Data 16 decembrie 2017 10:52:18
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

ifstream q("cmap.in");
ofstream w("cmap.out");


struct pct{
    int x,y;
}v[100100];

vector<pct> aux;

bool crescator(pct a, pct b)
{
    return (a.x<b.x);
}

double distanta(pct A, pct B)
{
    return ((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}


int main()
{
    int n;
    q>>n;
    q>>v[1].x>>v[1].y;
    aux.push_back(v[1]);
    for(int i=2;i<=n;i++)
    {
        q>>v[i].x>>v[i].y;
        aux.push_back(v[i]);
    }
    sort(aux.begin(),aux.end(),crescator);
    int lm = aux.size()/2; ///Acesta este dreapta x=lm a.i. sa avem diferenta intre Ps si Pd de maxim 1


        double min=distanta(v[1],v[2]); // trebuie sa initializam si noi cu ceva
        for(int i=1;i<n;i++)
            for(int j=i+1;j<=n;j++)
            {
                double dist = distanta(v[i],v[j]);
                if(dist<min) min=dist;
            }
        w<<setprecision(6)<<fixed<<sqrt(min);


    return 0;
}