Cod sursa(job #587866)

Utilizator biroBiro Alexandru biro Data 6 mai 2011 11:59:12
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<algorithm>
 
using namespace std;
 
float abbs(double A) {
  if (A<0)
    return -A ;
 return A ;
}
 
struct punct{
  double x;
  double y;
};
 
punct v[1001];
double p[1000009];
int cnt,cont=1;
int rez,n;
 
int main(){
  freopen("trapez.in","r",stdin);
  freopen("trapez.out","w",stdout);
  
  scanf("%d",&n) ;
   
  for(int i=1;i<=n;++i) {
    scanf("%lf%lf",&v[i].x,&v[i].y);
  }
  for(int i=1;i<n;++i) {
    for(int j=i+1;j<=n;++j) {
      if (v[i].x!=v[j].x) {
        p[++cnt]=(double)(v[i].y-v[j].y)/(v[i].x-v[j].x);
        p[cnt]=abbs(p[cnt]) ;
      }
     else p[++cnt]=-1 ;
    }
  }
  sort(p+1,p+cnt+1) ;
 for(int i=2;i<=cnt;++i) {
   if(p[i]==p[i-1])
      cont++;
    else {
      rez+=cont*(cont-1)/2 ;
      cont=1;
    }
  }
 
  printf("%d",rez) ;
   
  return 0 ;
}