Cod sursa(job #2294694)

Utilizator Dragomiralexandru621@yahoo.comDragomir ionut alexandru [email protected] Data 2 decembrie 2018 18:07:56
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("trapez.in") ;
ofstream g("trapez.out") ;
int n  ;
double a[3000000] ;
struct coordonate
{
    double x , y ;
}c[30000];
int main()
{
 f >> n ;
 for( int i = 1 ; i <= n ; i ++ )
    f >> c[i].x >> c[i].y ;
int l = 0 ;
double  nr = 0 ;
 for( int i = 1 ; i <= n - 1 ; i ++ )
    for( int j = i + 1 ; j <= n ; j ++ ){
      a[++l] = ( c[i].x - c[j].x ) / ( c[i].y - c[j].y ) ;
      //g << a[l] <<  " " ;
    }
    sort( a , a + l + 1 ) ;

 a[l + 1] = 0 ;
 for( int i = 2 ; i <= l ; i ++ ){
        int nrp = 1 ;
      while( a[i] == a[i - 1] ) {
       nrp ++ ;
      i ++ ;
      }
    nr += nrp * ( nrp - 1 ) / 2 ;
 }
g << nr ;
}