Cod sursa(job #2080487)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 3 decembrie 2017 00:01:23
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <bits/stdc++.h>
using namespace std;

void solve() {
    size_t point_count;
    cin >> point_count;

    vector< pair<int, int> > points(point_count);
    for (auto& it : points)
        cin >> it.first >> it.second;

    vector< long double > slopes;
    int vertical_slopes = 0;
    for (size_t i = 0; i < point_count; ++i) {
        for (size_t j = i + 1; j < point_count; ++j) {
            int delta_x = points[i].first - points[j].first;
            int delta_y = points[i].second - points[j].second;

            if (delta_x != 0)
                slopes.push_back((long double)delta_y * 1.0 / delta_x);
            else
                vertical_slopes++;
        }
    }

    int64_t solution = 1LL * vertical_slopes * (vertical_slopes - 1) / 2;
    sort(slopes.begin(), slopes.end());
    int counter = 1;
    for (size_t i = 1; i < slopes.size(); ++i)
        if (slopes[i] == slopes[i - 1])
            ++counter;
        else {
            solution += 1LL * counter * (counter - 1) / 2;
            counter = 1;
        }

    solution += 1LL * counter * (counter - 1) / 2;
    cout << solution << endl;
}

int main() {
    assert(freopen("trapez.in", "r", stdin));
    assert(freopen("trapez.out", "w", stdout));
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}