Cod sursa(job #3338900)

Utilizator parus_majorParus Major parus_major Data 5 februarie 2026 13:36:22
Problema Trapez Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <climits>
#include <map>

using namespace std;

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

const int MAXN = 1002;

map<pair<int, int>, int> cnt;
pair<int, int> v[MAXN];
int N;

pair<int, int> compute(int a, int b) {
    if (a < 0) { a = -a; b = -b; }
    if (b == 0) return { 1, 0 };
    if (a == 0) return { 0, 1 };
    
    int x = abs(a);
    int y = abs(b);
    int r = 0;
    while (y) {
        r = x % y;
        x = y;
        y = r;
    }
    return { a / x, b / x };
}

int main()
{
    fin >> N;
    for (int i = 0; i < N; ++i)
        fin >> v[i].first >> v[i].second;

    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            cnt[compute(v[i].first - v[j].first, v[i].second - v[j].second)]++;
        }
    }
    long long ans = 0LL;
    for (auto& [_, y] : cnt) {
        ans = ans + static_cast<long long>(y) * (y - 1) / 2;
    }
    fout << ans;
}