Cod sursa(job #772764)

Utilizator muresan_bogdanMuresan Bogdan muresan_bogdan Data 30 iulie 2012 18:06:05
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.51 kb
#include<fstream>
using namespace std;

ifstream fin("trapez.in");
ofstream fout("trapez.out");
int n, i, j, pereche, nr;
long long x[1000], y[1000], lung[500];
int main() {
    fin >> n;
    for(i = 0; i < n; i++) {
        fin >> x[i];
        fin >> y[i];
    }
    fin.close();
    for(i = 0; i < n; i++) {
        for(j = i + 1; j < n; j++) {
            if(x[i] == x[j]) {
                if(y[i] > y[j]) {
                    lung[pereche] = y[i] - y[j];
                }else {
                    lung[pereche] = y[j] - y[i];
                }
                pereche++;
            }
        }
    }
    if(pereche > 1) {
        nr = (pereche * (pereche - 1)) / 2;
    }
    for(i = 0; i < pereche; i++) {
        for(j = i + 1; j < pereche; j++) {
            if(lung[i] == lung[j]) {
                nr++;
            }
        }
    }
    pereche = 0;
    for(i = 0; i < n; i++) {
        for(j = i + 1; j < n; j++) {
            if(y[i] == y[j]) {
                if(x[i] > x[j]) {
                    lung[pereche] = x[i] - x[j];
                }else {
                    lung[pereche] = x[j] - x[i];
                }
                pereche++;
            }
        }
    }
    if(pereche > 1) {
        nr += (pereche * (pereche - 1)) / 2;
    }
    for(i = 0; i < pereche; i++) {
        for(j = i + 1; j < pereche; j++) {
            if(lung[i] == lung[j]) {
                nr++;
            }
        }
    }
    fout << nr;
    fout.close();
    return 0;
}