Cod sursa(job #2837246)

Utilizator AswVwsACamburu Luca AswVwsA Data 21 ianuarie 2022 23:02:31
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
//#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#define ll long long
using namespace std;

struct pct
{
    double x, y;
};

vector <double> 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;
    ll weird = 0;
    for (i = 1; i + 1 <= n; i++)
        for (j = i + 1; j <= n; j++)
        {
            if (a[j].x - a[i].x == 0)
                weird++;
            else
                v.push_back((a[j].y - a[i].y) / (a[j].x - a[i].x));
        }
    sort(v.begin(), v.end());
    /*for (i = 0; i < v.size(); i++)
        cout << v[i] << "\n";
    return 0;*/
    int first = 0, cnt = 1;
    ll ans = weird * (weird - 1) / 2;
    for (i = 1; i < v.size(); i++)
        if (v[first] == v[i])
            cnt++;
        else
        {
            ans += 1LL * cnt * (cnt - 1) / 2;
            first = i;
            cnt = 1;
        }
    ans += cnt * (cnt - 1) / 2;
    cout << ans;
}