Cod sursa(job #2047708)

Utilizator cyg_vladioanBirsan Vlad cyg_vladioan Data 25 octombrie 2017 10:14:57
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const double INF = 2.e9;
const double eps=1.e-14;
struct POINT
{
    double x , y;
};
POINT s[1005];
bool vertical (POINT P1 , POINT P2)
{
    return fabs(P1.x - P2.x) < eps;
}
double panta(POINT P1 , POINT P2)
{
    if(vertical(P1 , P2))
        return INF;
    return (P2.y - P1.y) / (P2.x - P1.x);
}
double v[1000005];
int main()
{
    freopen("trapez.in" , "r" , stdin);
    freopen("trapez.out" , "w" , stdout);
    int n , i , j , k;
    double tx , ty;
    scanf("%d" , &n);
    for(i = 1 ; i <= n ; i ++)
    {
        scanf("%lf%lf" , &tx , &ty);
        s[i].x = tx;
        s[i].y = ty;
    }
    k = 0;
    for(i = 1 ; i <= n ; i ++)
        for(j = i + 1 ; j <= n ; j ++)
            v[++ k] = panta(s[i]  , s[j]);
    sort(v + 1 , v + k + 1);
    int l , nr;
    nr = 0;
    for(i = 1 ; i <= k ; i ++)
    {
        l = 1;
        while(fabs(v[i + 1] - v[i]) < eps)
            l ++ , i ++;
        nr = nr + l * (l - 1) / 2;
    }
    printf("%d\n" , nr);
    return 0;
}