Cod sursa(job #1333895)

Utilizator razvan242Zoltan Razvan-Daniel razvan242 Data 3 februarie 2015 18:14:26
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <algorithm>

#define EPSILON 0.001
#define INFINIT 999999

using namespace std;

ifstream fin("trapez.in");
ofstream fout("trapez.out");

struct Punct
{
    int x, y;
};

int N;
Punct P[1001];
double Pante[1020100];

double Panta( Punct A, Punct B )
{
    if( B.x == A.x )
        return INFINIT;

    return (double)(B.y - A.y) / (B.x - A.x);
}

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

    int ind = 0;

    for(int i = 1; i < N; ++i)
        for( int j = i + 1; j <= N; ++j )
            Pante[++ind] = Panta( P[i], P[j] );

    sort( Pante + 1, Pante + 1 + ind );

    int S = 0;
    int L = 0;

    for( int i = 1; i < ind; ++i )
    {
        L = 0;
        while( Pante[i + 1] - Pante[i] < EPSILON )
            ++i, ++L;

        S += (L * (L + 1) / 2);
    }

    fout << S;

    return 0;
}