Cod sursa(job #2629020)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 18 iunie 2020 16:46:02
Problema Trapez Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <bits/stdc++.h>

using namespace std;

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

const int nmax = 1000;
int n, z;
long long ans = 0;

struct Point
{
    int x, y;
}v[nmax + 5];

struct Segment
{
    Point a, b;
}s[nmax * nmax + 5];

bool cmp(Segment s1, Segment s2)
{
    return 1LL * (s1.b.y - s1.a.y) * (s2.b.x - s2.a.x) <= 1LL * (s2.b.y - s2.a.y) * (s1.b.x - s1.a.x);
}

bool egal(Segment s1, Segment s2)
{
    return 1LL * (s1.b.y - s1.a.y) * (s2.b.x - s2.a.x) == 1LL * (s2.b.y - s2.a.y) * (s1.b.x - s1.a.x);
}

int main()
{
    fin >> n;
    for (int i = 1; i <= n; ++i)
    {
        fin >> v[i].x >> v[i].y;
        for (int j = i - 1; j >= 1; --j)
        {
            s[++z] = {v[i], v[j]};
        }
    }
    sort(s + 1, s + z + 1, cmp);
    for (int i = 1; i <= z; ++i)
    {
        int j = i + 1;
        while (egal(s[i], s[j]) && j <= z) ++j;
        --j;
        int contor = j - i + 1;
        ans = 1LL * ans + 1LL * contor * (contor - 1) / 2;
        i = j;
    }
    fout << ans;
    fin.close();
    fout.close();
    return 0;
}