Cod sursa(job #1706802)

Utilizator tiberiu225Iancu Tiberiu tiberiu225 Data 23 mai 2016 11:54:05
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <bits/stdc++.h>
using namespace std;

const double INF = 2.e9;
const double eps = 1.e-14;

struct POINT
{
    int x, y;
}v[1005];

double panta (POINT A, POINT B)
{
    if(fabs(A.x - B.x) < eps)
        return INF;
    return 1.0 * (B.y - A.y) / (B.x - A.x) * 1.0;
}

bool paralele (POINT A, POINT B, POINT C, POINT D)
{
    return (fabs(panta(A, B) - panta(C, D)) < eps);
}

double p[500000];

bool cmp(double a, double b)
{
    return (a - b) <= -eps;
}

int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n; cin >> n;

    for(int i = 1; i <= n; ++i){
        int x, y; cin >> x >> y;
        v[i].x = x; v[i].y = y;
    }

    int nr = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = i + 1; j <= n; ++j){
            p[++nr] = panta(v[i], v[j]);
        }
    }

    sort(p + 1, p + nr + 1);

    int l = 1;
    int ans = 0;
    for(int i = 1; i < nr; ++i){
        if(fabs(p[i] - p[i + 1]) < eps){
            l++;
        }else{
            ans += l * (l - 1) / 2;
            l = 1;
        }
    }

    cout << ans;
    return 0;
}