Cod sursa(job #2296267)

Utilizator cahemanCasian Patrascanu caheman Data 4 decembrie 2018 16:25:27
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<cstdio>
#include<algorithm>

using namespace std;

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

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]) / (double)(y[i] - y[j]);
    sort(perechi + 1, perechi + nr + 1);
    for(i = 1; i <= nr; ++ i)
    {
        nc = 1;
        while(perechi[i] == perechi[i + 1] && i < nr)
        {
            ++ i;
            ++ nc;
        }
        sum = sum + (long long) (((long long)nc * ((long long)nc - 1))/2);
    }
    printf("%lld", sum);
    return 0;
}