Cod sursa(job #2837227)

Utilizator AswVwsACamburu Luca AswVwsA Data 21 ianuarie 2022 22:14:42
Problema Trapez Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
//#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#define ll long long
using namespace std;
struct panta
{
    int sus, jos;
};

struct pct
{
    int x, y;
};

bool cmp(panta a, panta b)
{
    return a.sus * b.jos < a.jos * b.sus;
}

bool egal(panta a, panta b)
{
    return a.sus * b.jos == a.jos * b.sus;
}
vector <panta> v;

const int NMAX = 1003;
pct a[NMAX];
int main()
{
    ifstream cin("trapez.in");
    ofstream cout("trapez.out");
    int n, i, j;
    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> a[i].x >> a[i].y;
    for (i = 1; i + 1 <= n; i++)
        for (j = i + 1; j <= n; j++)
        {
            panta aux;
            aux.sus = a[j].y - a[i].y;
            aux.jos = a[j].x - a[i].x;
            v.push_back(aux);
        }
    sort(v.begin(), v.end(), cmp);
    int first = 0, cnt = 1;
    long long ans = 0;
    for (i = 1; i < v.size(); i++)
        if (egal(v[first], v[i]))
            cnt++;
        else
        {
            ans += 1LL * cnt * (cnt - 1) / 2;
            first = i;
            cnt = 1;
        }
    ans += cnt * (cnt - 1) / 2;
    cout << ans;
}