Cod sursa(job #2117871)

Utilizator LucaSeriSeritan Luca LucaSeri Data 29 ianuarie 2018 19:14:27
Problema Cele mai apropiate puncte din plan Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.59 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 10;

class Reader {
  public:
    Reader(const string& filename):
            m_stream(filename),
            m_pos(kBufferSize - 1),
            m_buffer(new char[kBufferSize]) {
        next();
    }

    Reader& operator>>(int& value) {
        value = 0;
        while (current() < '0' || current() > '9')
            next();
        while (current() >= '0' && current() <= '9') {
            value = value * 10 + current() - '0';
            next();
        }
        return *this;
    }

  private:
    const int kBufferSize = 32768;

    char current() {
        return m_buffer[m_pos];
    }

    void next() {
        if (!(++m_pos != kBufferSize)) {
            m_stream.read(m_buffer.get(), kBufferSize);
            m_pos = 0;
        }
    }

    ifstream m_stream;
    int m_pos;
    unique_ptr<char[]> m_buffer;
};

pair< int, int > v[MAXN];

double dist(pair< int, int >& a, pair< int, int >& b){
    return sqrt(1.0*(a.first - b.first) * (a.first - b.first) + 1.0*(a.second - b.second) * (a.second - b.second));
}

Reader f("cmap.in");
ofstream g("cmap.out");

int main(){
    int n;
    f >> n;
    for(int i = 0; i < n; ++i){
        f >> v[i].first >> v[i].second;
    }

    sort(v, v + n);
    double best = dist(v[0], v[1]);

    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n && v[j].first - v[i].first < best; ++j){
            best = min(best, dist(v[i], v[j]));
        }
    }

    g << setprecision(10) << fixed << best;
    return 0;
}