Cod sursa(job #1162205)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 31 martie 2014 18:22:37
Problema Trapez Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>

using namespace std;

const int Nmax = 1000;
const double EPS = 1e-9;

typedef long long ll;

#define x first
#define y second
#define Point pair<ll,ll>

bool eq( Point a, Point b )
{
    return ( a.x * b.y == b.x * a.y );
}

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    if (a.x * b.y == b.x * a.y) return 0;
    bool r = (a.x * b.y < b.x * a.y);
    if (b.y < 0) r = !r;
    if (a.y < 0) r = !r;
    return r;
}

Point slopes[Nmax * Nmax];
Point P[Nmax + 1];
int N;

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

    f >> N;

    for ( int i = 1; i <= N; ++i )
            f >> P[i].x >> P[i].y;

    int M = 0;

    for ( int i = 1; i < N; ++i )
            for ( int j = i + 1; j <= N; ++j )
                    slopes[ ++M ] = Point( P[i].x - P[j].x, P[i].y - P[j].y );

    sort( slopes + 1, slopes + 1 + M, cmp );

    ll contor = 1;
    ll sol = 0;

    for ( int i = 2; i <= M; ++i )
    {
        if ( eq( slopes[i - 1], slopes[i] ) )
                contor++;
        else
        {
            sol += 1LL * contor * ( contor - 1 ) / 2LL;
            contor = 1;
        }
    }

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

    g << sol << "\n";

    return 0;
}