Cod sursa(job #2980925)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 16 februarie 2023 22:09:42
Problema Trapez Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <fstream>
#include <algorithm>
#include <map>

using namespace std;

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

const int INF = 2e9 + 1;

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];

int 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;
    v[m + 1].x = v[m + 1].y = -INF;
    for (int i = 2; i <= m + 1; ++i)
    {
        if (v[i] == v[i - 1])
            ++nr;
        else
        {
            res = res + (nr - 1) * nr / 2;
            nr = 1;
        }
    }
    cout << res << '\n';
    return 0;
}