Cod sursa(job #2980927)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 16 februarie 2023 22:13:15
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <fstream>
#include <algorithm>
#define int long long

using namespace std;

ifstream cin ("trapez.in");
ofstream cout ("trapez.out");

const int N = 1e3;

class varza
{
public:
    int x, y;
    friend istream& operator >> (istream &is, varza &a)
    {
        is >> a.x >> a.y;
        return is;
    }
    bool operator < (const varza &a)const
    {
        if (a.x != x)
            return x < a.x;
        return y < a.y;
    }
} a[N + 1];

int n, res, m;

class lil
{
public:
    int x, y;
    bool operator < (const lil &a)const
    {
        return y * a.x < x * a.y;
    }
    bool operator == (const lil &a)const
    {
        return (a.x * y == a.y * x);
    }
} v[N * N + 1];

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    sort (a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j)
            v[++m].y = a[j].y - a[i].y, v[m].x = a[j].x - a[i].x;
    sort (v + 1, v + m + 1);
    int nr = 1;
    for (int i = 2; i <= m; ++i)
    {
        if (v[i] == v[i - 1])
            ++nr;
        else
            res = res + (nr - 1) * nr / 2, nr = 1;
    }
    if (nr > 1)
        res += (nr - 1) * nr / 2;
    cout << res << '\n';
    return 0;
}