Cod sursa(job #940496)

Utilizator matei_cChristescu Matei matei_c Data 16 aprilie 2013 13:49:37
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

#define maxn 1001
#define maxp 1000001
#define inf ( 1 << 30 )

struct punct
{
    int x, y ;
};

int n ;
punct v[maxn] ;

int nrp ;
double panta[maxp] ;

double ppanta( punct A, punct B )
{
    if( A.x == B.x )
        return inf ;

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

void citire()
{
    freopen("trapez.in", "r", stdin);
    freopen("trapez.out", "w", stdout);

    cin >> n ;

    for(int i = 1; i <= n; ++i )
        cin >> v[i].x >> v[i].y ;
}

void calc_pante()
{
    for(int i = 1; i <= n; ++i )
        for(int j = i + 1 ; j <= n; ++j )
            panta[ ++nrp ] = ppanta( v[i], v[j] ) ;

    sort( panta + 1, panta + nrp + 1 ) ;
}

void afisare()
{
    int act = 0 ;
    int sol = 0 ;

    for(int i = 1; i < nrp; ++i )
    {
        if( panta[i] == panta[ i + 1 ] )
            ++act ;
        else
        {
            sol += ( act * ( act - 1 ) / 2 ) ;
            act = 1 ;
        }
    }

    cout << sol ;
}

int main()
{
    citire() ;

    calc_pante() ;

    afisare() ;

    return 0 ;
}