Cod sursa(job #2594570)

Utilizator andreiomd1Onut Andrei andreiomd1 Data 6 aprilie 2020 12:53:12
Problema Trapez Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <fstream>
#include <unordered_map>
#include <algorithm>
#include <cmath>

using namespace std;

ifstream f("trapez.in");
ofstream g("trapez.out");

typedef pair < int, int > PII;

const long double PI = acos(-1);
const int NMAX = 1e3 + 5;

int N;
PII A[NMAX];

unordered_map < long double, int > mp;

long long ans = 0;

static inline void Read ()
{
    f.tie(nullptr);

    f >> N;

    for(int i = 1; i <= N; ++i)
        f >> A[i].first >> A[i].second;

    return;
}

static inline void Precalculation ()
{
    for(int i = 1; i < N; ++i)
        for(int j = i + 1; j <= N; ++j)
        {
            long double Numa = A[j].second - A[i].second;
            long long Numb = A[j].first - A[i].first;

            long double X = ((Numb) ? (Numa / Numb) : 1e9);

            ++mp[X];
        }

    return;
}

static inline void Solve ()
{
    for(auto it : mp)
        if(it.second > 1)
            ans += 1LL * (it.second * (it.second - 1LL)) / 2LL;

    g << ans << '\n';

    return;
}

int main()
{
    Read();

    Precalculation();

    Solve();

    return 0;
}