Cod sursa(job #1494804)

Utilizator FairPlay94George Cioroiu FairPlay94 Data 1 octombrie 2015 21:19:11
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <cstdio>
#include <iostream>
#include <set>
#include <climits>
#include <map>
#include <algorithm>

using namespace std;

bool f(pair<long long, long long> a, pair<long long, long long> b) {
    return (a.second * b.first < a.first * b.second);
}

bool g(pair<long long, long long> a, pair<long long, long long> b) {
    return (a.second * b.first == a.first * b.second);
}

int main() {
    freopen("trapez.in", "r", stdin);
    freopen("trapez.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    long long x[1005], y[1005];
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }
    pair<long long, long long> v[1000005];
    int l = n * (n - 1) / 2, c = 1;
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++, c++) {
            v[c].first = x[i] - x[j];
            v[c].second = y[i] - y[j];
        }
    }
    sort(v + 1, v + l + 1, f);
    long long ans = 0;
    for (int i = 1; i <= l; i++) {
        int j = i + 1;
        c = 1;
        while (j <= l && g(v[i], v[j])) {
            c++;
            j++;
        }
        ans += c * (c - 1) / 2;
    }
    cout << ans;

    return 0;
}