Cod sursa(job #1798896)

Utilizator elffikkVasile Ermicioi elffikk Data 5 noiembrie 2016 15:47:02
Problema Cele mai apropiate puncte din plan Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

struct Point {
    int x, y;
};

bool cmp(Point a, Point b) {
    return a.x<b.x || a.x==b.x && a.y<b.y;
}

double dist(Point a, Point b) {
    return pow(a.x-b.x, 2)+pow(a.y-b.y, 2);
}

main() {
    ifstream cin("cmap.in");
    ofstream cout("cmap.out");
    int n;
    cin>>n;
    vector<Point> a(n);
    for (int i = 0; i < n; i++) {
        cin>>a[i].x>>a[i].y;
    }
    sort(a.begin(), a.end(), cmp);
    double d = dist(a[0], a[1]);
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (abs(a[j].x-a[i].x) >= d) {
                break;
            }
            if ( dist(a[i], a[j]) < d ) {
                d = dist(a[i], a[j]);
            }
        }
    }
    cout<<fixed;
    cout<<setprecision(9)<<sqrt(d);

}