Cod sursa(job #1802804)

Utilizator stefanmereutaStefan Mereuta stefanmereuta Data 10 noiembrie 2016 17:36:23
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
#include <algorithm>

using namespace std;

struct punct {
    int x, y;
};

int main()
{
    ifstream fin("trapez.in");
    ofstream fout("trapez.out");

    int N;
    punct v[1000];
    float pante[1000000] = {0};

    fin >> N;

    for (int i = 0; i < N; i++) {
        fin >> v[i].x >> v[i].y;

        for (int j = 0; j < i; j++) {
            if (v[i].x == v[j].x) {
                pante[1000 * i + j] = pante[1000 * j + i] = 2000000.0;
            } else {
                pante[1000 *i + j] = pante[1000 * j + i] = (float) (v[j].y - v[i].y) / (v[j].x - v[i].x);
            }
        }
    }

    sort(pante, pante + 1000000);

    int i = 0, x, nr_trapeze = 0;

    while (i < 2 * N) {
        x = i;
        i++;
        while (i < 2 * N && pante[i] == pante[x]) {
            i++;
        }

        nr_trapeze += (i - x) / 2 * ((i - x) / 2 - 1) / 2;
    }

    fout << nr_trapeze;

    fin.close();
    fout.close();
    return 0;
}