Cod sursa(job #1899327)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 2 martie 2017 17:30:32
Problema Trapez Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#define eps (long double)1e-10
#define INF 2000000001

using namespace std;

const int N = 1010 ;
struct Point {
    int x , y ;
};

Point pct [ N ];

vector < long double > drepte ;
vector < long double >::iterator it ;

bool cmp ( pair< int ,int > a , pair < int , int > b ){

    return (long double )a.second/a.first  < (long double) b.second/b.first  ;


}

long double  a , b ;
int main(){
    int n , i , j;
    int sol = 0 ;
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);

    scanf("%d",&n);

    for ( i = 0 ; i < n ; i++ ){
        scanf("%d%d",&pct[ i ].x ,&pct[ i ].y );
    }

    for ( i = 0 ; i < n ; i ++ ){
        for ( j = i + 1 ; j < n ; j ++ ){

            if (  pct [j].x - pct [i].x == 0 ){
                drepte.push_back( INF );
                continue;
            }

            drepte.push_back(  ( (long double )pct[j].y - pct[i].y ) / ( (long double)pct [j].x - pct [i].x )  );
        }
    }

    sort( drepte.begin() , drepte.end()  );

    int nrdr = 1 ;

    for ( it = drepte.begin() ; it + 1 != drepte.end() ; it++ ){
        a = *it ;
        b = *( it + 1 );

        if ( !( a - b < eps && a - b > -eps ) ){
            sol += nrdr * ( nrdr - 1 )/2 ;
            nrdr = 0 ;
        }
        nrdr ++ ;
    }
    sol += nrdr * ( nrdr - 1 )/2 ;

    printf("%d",sol );

    return 0;

}