Cod sursa(job #1494839)

Utilizator FairPlay94George Cioroiu FairPlay94 Data 1 octombrie 2015 21:44:26
Problema Trapez Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.44 kb
#include <cstdio>
#include <iostream>
#include <set>
#include <climits>
#include <map>
#include <algorithm>
#include <list>
#include <vector>
#include <utility>

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];
    }
    vector<pair<long long, long long> > v;
    int l = n * (n - 1) / 2;
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int xc = x[i] - x[j];
            int yc = y[i] - y[j];
            if (yc < 0) {
                yc = -yc;
                xc = -xc;
            }
            pair<long long, long long> p = make_pair(xc, yc);
            v.push_back(p);
        }
    }
    sort(v.begin(), v.end(), f);
    long long ans = 0;
    for (int i = 0; i < l; i++) {
        int j = i + 1;
        int c = 1;
        while (j < l && g(v[i], v[j])) {
            c++;
            j++;
        }
        ans += c * (c - 1) / 2;
    }
    cout << ans;

    return 0;
}