Cod sursa(job #2764246)

Utilizator DordeDorde Matei Dorde Data 20 iulie 2021 00:40:42
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.56 kb
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int const N = 1e6 + 3;
typedef long long ll;
struct Point{
    ll x , y;
    Point (){
        x = y = 0LL;
    }
    Point (ll X , ll Y){
        x = X , y = Y;
    }
};
struct Line{
    Point a , b;
    ll v1 , v2;
    Line (){

    }
    Line (Point A , Point B){
        a = A , b = B;
        v1 = A.y - B.y;
        v2 = A.x - B.x;
    }
    bool operator == (Line r) const{
        return v1 * r.v2 == v2 * r.v1;
    }
    bool operator < (Line r) const{
        return v1 * r.v2 < v2 * r.v1;
    }
};
Point V [1001];
Line v [N];
int main()
{
    freopen ("trapez.in" , "r" , stdin);
    freopen ("trapez.out" , "w" , stdout);
    int n;
    scanf ("%d" , &n);
    for(int i = 1 ; i <= n ; ++ i){
        ll a , b;
        scanf ("%lld%lld" , &a , &b);
        Point P (a , b);
        V [i] = P;
    }
    int k = 0;
    for(int i = 1 ; i < n ; ++ i)
        for(int j = i + 1 ; j <= n ; ++ j){
            Line x (V [i] , V [j]);
            v [++ k] = x;
        }
    sort (v + 1 , v + 1 + k);
    ll ans = 0LL;
    Line Last;
    int lg;
    for(int i = 1 ; i <= n ; ++ i){
        if (i == 1){
            Last = v [1];
            lg = 1;
            continue;
        }
        if (v [i] == Last)
            ++ lg;
        else{
            ans = ans + 1LL * lg * (lg - 1) / 2LL;
            Last = v [i];
            lg = 1;
        }
    }
    ans = ans + 1LL * lg * (lg - 1) / 2LL;
    printf ("%lld" , ans);
    return 0;
}