Cod sursa(job #2876206)

Utilizator AlexNicuNicu Alexandru AlexNicu Data 23 martie 2022 09:52:22
Problema Trapez Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define NMAX 1001

#define INF (1LL<<50)

struct POINT {
    int x, y;
};

double getpanta( const POINT& a, const POINT& b ) {
    if ( a.x == b.x )
        return INF;
    return ( (double)b.y - a.y ) / ( b.x - a.x );
}

struct DREAPTA {
    double panta;
    bool operator < ( const DREAPTA& other ) const {
        return panta < other.panta;
    }
};

vector<DREAPTA> drepte;

POINT v[NMAX];

int main() {
    long long n, i, j, ans;
    double 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 == drepte[j].panta )
            j++;
        ans += ( j - i ) * ( j - i - 1 ) / 2;
    }
    cout << ans;
    return 0;
}