Cod sursa(job #1330071)

Utilizator razvan242Zoltan Razvan-Daniel razvan242 Data 30 ianuarie 2015 12:34:18
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 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[1000001];

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] = (double)Panta( P[i], P[j] );

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

    int S = 0;
    int L = 1;

    for( int i = 2; i <= ind; ++i )
    {
        if( Pante[i] - Pante[i - 1] < EPSILON )
            L++;
        else
        {
            if( L >= 2 )
                S += L * (L - 1) / 2;
            L = 1;
        }
    }

    fout << S;

    return 0;
}