Cod sursa(job #1295062)

Utilizator RaduVisanRadu Visan RaduVisan Data 18 decembrie 2014 19:00:03
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <cstdio>
#include <algorithm>
using namespace std;

const int NMAX = 1010;

int N, X[NMAX], Y[NMAX], Ans, K;

struct Slope
{
    int DX, DY;
}S[NMAX * NMAX];

struct Comp
{
    bool operator() (const Slope &A, const Slope &B) const
    {
        return 1LL * A.DY * B.DX < 1LL * A.DX * B.DY;
    }
};

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

    scanf("%i", &N);
    for(int i = 1; i <= N; ++ i)
        scanf("%i %i", &X[i], &Y[i]);

    for(int i = 1; i <= N; ++ i)
        for(int j = i + 1; j <= N; ++ j)
            S[++ K].DX = X[j] - X[i], S[K].DY = Y[j] - Y[i];

    sort(S + 1, S + K + 1, Comp());

    S[0].DX = S[1].DX - 1;
    S[0].DY = S[1].DY - 1;

    int CntEqual = 0;
    for(int i = 1; i <= N; ++ i)
        if(1LL * S[i - 1].DY * S[i].DX == 1LL * S[i - 1].DX * S[i].DY)
            CntEqual ++;
        else
        {
            Ans += (CntEqual * (CntEqual - 1)) / 2;
            CntEqual = 1;
        }

    Ans += (CntEqual * (CntEqual - 1)) / 2;

    printf("%i\n", Ans);
}