Cod sursa(job #1913617)

Utilizator VladG26Ene Vlad-Mihai VladG26 Data 8 martie 2017 13:22:25
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int n;

struct punct
{
    int x,y;
} vPuncte[100002];
vector<punct> ST,DR;
bool cmpX(punct p1,punct p2)
{
    return p1.x<p2.x;
}
bool cmpY(punct p1,punct p2)
{
    return p1.y<p2.y;
}
double dist(punct p1,punct p2)
{
    double rez;
    rez=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
    return rez;
}

void citire()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&vPuncte[i].x,&vPuncte[i].y);
    }
}

double solve()
{
    sort(vPuncte+1,vPuncte+n+1,cmpX);
    double rez;
    rez=dist(vPuncte[1],vPuncte[2]);
    for(int i=1; i<n; i++)
        for(int j=i+1; j<=n&&vPuncte[j].x-vPuncte[i].x<rez; j++)
        {
            rez=min(rez,dist(vPuncte[i],vPuncte[j]));
        }
    return rez;
}
int main()
{
    freopen("cmap.in","r",stdin);
    freopen("cmap.out","w",stdout);
    citire();
    printf("%lf",solve());
    return 0;
}