Cod sursa(job #1898349)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 1 martie 2017 22:46:58
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

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

Point pct [ N ];

vector < pair <int ,int > > drepte ;
vector < pair <int ,int > >::iterator it ;

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

    return 1LL *a.second * b.first - 1LL*b.second * a.first < 0 ;


}

pair <int ,int > 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 ++ ){
            drepte.push_back( make_pair( abs(pct [j].x - pct [i].x) ,abs( pct[j].y - pct[i].y ) )  );
        }
    }

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

    int nrdr = 0 ;

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

        if (  1LL *a.second * b.first - 1LL * b.second * a.first != 0 ){
            sol += nrdr * ( nrdr - 1 )/2 ;
            nrdr = 0 ;
        }
        nrdr ++ ;
    }
    sol += nrdr * ( nrdr - 1 )/2 ;

    printf("%d",sol );

    return 0;

}