Cod sursa(job #2404580)

Utilizator andreiomd1Onut Andrei andreiomd1 Data 13 aprilie 2019 08:52:39
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda sim_info14 Marime 1.07 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream f("trapez.in");
ofstream g("trapez.out");

const int NMAX=1e3+2, INF=1e6;

int N, M;

pair < long double, long double > A[NMAX];

long double V[NMAX*NMAX];

long long ans=0;

inline void Read ()
{
    f.tie(NULL);

    f>>N;

    for(int i=1; i<=N; ++i)
        f>>A[i].first>>A[i].second;

    return;
}

inline void Precalculation ()
{
    for(int i=1; i<N; ++i)
        for(int j=i+1; j<=N; ++j)
            if(A[i].first != A[j].first)
                V[++M]=(long double)((A[i].second - A[j].second) / (A[i].first - A[j].first));
            else V[++M]=INF;

    sort(V+1, V+M+1);

    return;
}

inline void Solve ()
{
    long long lc=1;

    for(int i=2; i<=M; ++i)
        if(V[i] == V[i-1])
            ++lc;
        else
        {
            ans+=1LL*(lc*(lc-1))/2;

            lc=1;
        }

    ans+=1LL*(lc*(lc-1))/2;

    g<<ans<<'\n';

    return;
}

int main()
{
    Read();

    Precalculation();

    Solve();

    return 0;
}