Cod sursa(job #414393)

Utilizator petrecgClinciu Glisca Petre petrecg Data 10 martie 2010 00:00:22
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <stdio.h>
long long x[1011],y[1011],a[1011000],b[1011000],n,i,j,c,l;
long long nr;
int main()
{freopen("trapez.in","r",stdin);
 freopen("trapez.out","w",stdout);
 fscanf(stdin,"%ld",&n);
 for(i=1;i<=n;i++)
  {fscanf(stdin,"%lld%lld",&x[i],&y[i]);
   for(j=1;j<i;j++)
    {a[++l]=y[i]-y[j];b[l]=x[i]-x[j];
    }
  }
 for(i=1;i<l;i++)
  for(j=i+1;j<=l;j++)
   {if((long long)a[i]*b[j]>(long long)a[j]*b[i]){c=a[i];a[i]=a[j];a[j]=c;c=b[i];b[i]=b[j];b[j]=c;}
   }
 n=0;
 for(i=2;i<=l;i++)
  {if((long long)a[i]*b[i-1]==(long long)b[i]*a[i-1])n++;else {nr+=n*(n+1)/2;n=0;}
  }
 nr+=n*(n+1)/2;
 fprintf(stdout,"%lld",nr);
 fclose(stdin);fclose(stdout);
 return 0;
}