Cod sursa(job #1918263)

Utilizator mworkgMaxim Stepanov mworkg Data 9 martie 2017 14:45:31
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <math.h>

using namespace std;

ifstream cin("cmap.in");
ofstream cout("cmap.out");

double distanta(long n1, long m1, long n2, long m2) {
    return sqrt(pow((n1-n2),2)+pow((m1-m2),2));
}

int main() {
    long long int puncte;
    double punct[100000][3];
    double dis,totaldis;
    cin >> puncte;
    for (int i = 0; i < puncte; i++) {
        cin >> punct[i][1] >> punct[i][2];
    }
    for (int i = 0; i < puncte; i++) {
        for (int j = i; j < puncte; j++) {
            // Itteration
            if (i != j) {
            dis = distanta(punct[i][1], punct[i][2], punct[j][1], punct[j][2]);
            if ((dis < totaldis) || (totaldis == 0)) { totaldis = dis; }
                if ((dis < punct[i][3]) || (punct[i][3] == 0)) {
                    punct[i][3] = dis;
                }    
            }
            // Itteration
        }
    }

    cout << totaldis;
    return 0;
}