Cod sursa(job #2410212)

Utilizator AndoneAlexandruAndone Alexandru AndoneAlexandru Data 19 aprilie 2019 20:06:44
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <map>
using namespace std;

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

int n;

struct puncte{
    int x, y;
}pct[1005];

map <pair <int, int>, int> p;

int cmmdc(int x, int y) {
    if (y == 0) return 1;
    return cmmdc(y, x % y);
}

int comb(int n) {
    return n * (n - 1) / 2;
}

int main() {
    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> pct[i].x >> pct[i].y;

    int rez = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            int a = pct[i].y - pct[j].y;
            int b = pct[i].x - pct[j].y;
            int cmd = cmmdc(a, b);

            a /= cmd;
            b /= cmd;

            p[{a, b}]++;
        }
    }

    for (auto it:p) {
        rez += comb(it.second);
    }

    cout << rez;
    return 0;
}