Cod sursa(job #2876218)

Utilizator AlexNicuNicu Alexandru AlexNicu Data 23 martie 2022 10:01:03
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda masonii Marime 1.17 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

#define NMAX 1001

#define INF (1LL<<50)

#define EPS 0.00000000000001

struct POINT {
    int x, y;
};

POINT getpanta( const POINT& a, const POINT& b ) {
    return {b.y - a.y, b.x - a.x };
}

struct DREAPTA {
    POINT panta;
    bool operator < ( const DREAPTA& other ) const {
        return panta.x * other.panta.y < panta.y * other.panta.x;
    }
};

vector<DREAPTA> drepte;

POINT v[NMAX];

int main() {
    long long n, i, j, ans;
    POINT x;
    cin >> n;
    for ( i = 0; i < n; i++ ) {
        cin >> v[i].x >> v[i].y;
    }
    for ( i = 1; i < n; i++ ) {
        for ( j = 0; j < i; j++ ) {
            x = getpanta( v[i], v[j] );
            drepte.push_back({x});
        }
    }
    sort ( drepte.begin(), drepte.end() );
    ans = 0;
    for ( i = 1; i < drepte.size(); i++ ) {
        j = i;
        while ( j < drepte.size() && drepte[i].panta.x * drepte[j].panta.y == drepte[i].panta.y * drepte[j].panta.x )
            j++;
        ans += ( j - i ) * ( j - i - 1 ) / 2;
    }
    cout << ans;
    return 0;
}