Cod sursa(job #2296228)

Utilizator cahemanCasian Patrascanu caheman Data 4 decembrie 2018 16:15:11
Problema Trapez Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.53 kb
#include<cstdio>
#include<algorithm>

using namespace std;

struct dr
{
    int x;
    int y;
};

int x[1005], y[1005];
double perechi[1000000];

bool cmp(dr a, dr b)
{
    if(a.y == 0 || b.y == 0)
    {
        if(a.y == 0 && b.y == 0)
            return 0;
        else
            if(a.y == 0)
                return 0;
            else
                return 1;
    }
    if((double) a.x / a.y > (double)a.x / b.y)
        return 1;
    else
        return 0;
}

int same(dr a, dr b)
{
    if(a.y == 0 || b.y == 0)
    {
        if(a.y == 0 && b.y == 0)
            return 1;
        else
            return 0;
    }
    if((double) a.x / a.y - (double)b.x / b.y <= 0.00001 && (double) a.x / a.y - (double)b.x / b.y >= 0 - 0.00001)
        return 1;
    else
        return 0;
}

int main()
{
    freopen("trapez.in", "r", stdin);
    freopen("trapez.out", "w", stdout);
    int n, i, j, nr = 0, nc;
    long long a, b, sum = 0;
    scanf("%d", &n);
    for(i = 1; i <= n; ++ i)
        scanf("%d%d", &x[i], &y[i]);
    for(i = 1; i < n; ++ i)
        for(j = i + 1; j <= n; ++ j)
        {
            perechi[++ nr] = (double)(x[i] - x[j]) / (y[i] - y[j]);
        }
    sort(perechi + 1, perechi + nr + 1);
    for(i = 1; i <= nr; ++ i)
    {
        nc = 0;
        while(perechi[i] == perechi[i + nc + 1] && i + nc < nr)
        {
            ++ nc;
        }
        sum = sum + (long long) (((long long)nc * ((long long)nc + 1))/2);
    }
    printf("%lld", sum);
    return 0;
}