Cod sursa(job #941822)

Utilizator superman_01Avramescu Cristian superman_01 Data 19 aprilie 2013 20:26:30
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include<cstdio>
#include<vector>
#include<algorithm>

#define NMAX 1005
#define INF 0x3f3f3f3f

FILE *f=fopen("trapez.in","r");
FILE *g=fopen("trapez.out","w");

using namespace std;


int n,Answer;
vector <double> slope;
struct point {
   int x,y;
};
point v[NMAX];

inline double Incline ( const point A , const point B )
{
    if(A.x == B.x )
		return 1<<30;
	
   return (double)( B.y-A.y)/(B.x-A.x);
}
void Read( void )
{
 fscanf(f,"%d",&n);
 for( int i(1) ; i <= n ; ++i )
 {
    fscanf(f,"%d%d",&v[i].x,&v[i].y);
	for(int ii(1) ; ii < i ; ++ii )
		 slope.push_back(Incline(v[i],v[ii]));
 }
  fclose(f);
}


void Solve ( void )
{
 
    sort(slope.begin(),slope.end());

   for( vector<double>::iterator it=slope.begin() ; it!=slope.end() ; ++it  )
   {
      double  val=*it;
       int ccount=1;
       ++it;
       while( val == *it && it!=slope.end())
        ++ccount,++it;
        Answer+=ccount *( ccount-1 )/2;
    --it;
   }

}
void Write ( void )
{
  fprintf(g,"%d",Answer);
  fclose(g);
}
int main ( void )
{
    Read();
    Solve();
    Write();
    return 0;
}