Cod sursa(job #2410215)

Utilizator AndoneAlexandruAndone Alexandru AndoneAlexandru Data 19 aprilie 2019 20:10:50
Problema Trapez Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 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){
    int r=0;
    while(y){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}

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

int main() {
    ios::sync_with_stdio(false);

    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].x;
            int cmd = cmmdc(a, b);

            a /= cmd;
            b /= cmd;

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

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

    cout << rez;
    return 0;
}