Cod sursa(job #1360906)

Utilizator vladdy47Bucur Vlad Andrei vladdy47 Data 25 februarie 2015 18:41:07
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
# include <cstdio>
# include <algorithm>
# include <climits>
# include <vector>

#define eps 1e-12

using namespace std;

int n,m,i,x,y,j,nr = 0;

long long sol;

double P[1005];


vector < pair <int, int> > V;



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

    scanf("%d",&n);
   // V.push_back(make_pair(0,0));
    for (i = 1; i <= n; i++)
    {
        scanf("%d%d",&x,&y);
        V.push_back(make_pair(x,y));
    }


    for (i = 1; i < n-1; i++)
        for (j = i + 1; j < n; j++)
            if (V[i].first - V[j].first != 0)
                P[++m] = double( (V[i].second - V[j].second) / (V[i].first - V[j].first) );
            else P[++m] = INT_MAX;

    sort (P + 1, P + m + 1);

    i = 2;

    while ( i <= m )
    {
        nr = 1;
        while ( P[i] - P[i-1] < eps && P[i] - P[i-1] > -eps)
        {
            i++;
            nr++;
        }


        sol += 1LL * nr * (nr - 1) / 2;


        if (nr == 1) i++;
    }

    printf("%lld",sol);

    return 0;
}