Cod sursa(job #2629104)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 19 iunie 2020 00:06:13
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

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

const int nmax = 1000;
int n, z;
double p[nmax * nmax + 5];
long long ans = 0;

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

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