Cod sursa(job #1142861)

Utilizator dobrebogdanDobre Bogdan Mihai dobrebogdan Data 14 martie 2014 12:26:36
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include<cstdio>
#include<algorithm>
#define eps 1.e-14
const double inf=(1LL<<31)-1;
double f[1000005];
struct sp
{
    double x,y;
}v[1005];
using namespace std;
bool cmp(double a,double b)
{
return a-b<eps;
}
int main()
{
   freopen("trapez.in","r",stdin);
   freopen("trapez.out","w",stdout);
   int n,i,m=0,l=1,j,sl=0;
   scanf("%d",&n);
   for(i=1;i<=n;i++)
    scanf("%lf%lf",&v[i].x,&v[i].y);
     for(i=1;i<=n;i++)
   {
        for(j=1;j<i;j++)
        {
         m++;
         if(v[i].y-v[j].y<=-eps || v[i].y-v[j].y>=eps)
         f[m]=(v[i].x-v[j].x)/(v[i].y-v[j].y);
         else
         {
         f[m]=inf;
         }
        }
   }
   sort(f+1,f+m+1,cmp);
   for(i=1;i<m;i++)
   if(f[i+1]-f[i]<eps && f[i+1]-f[i]>-eps)
   {
       l++;
   }
   else
   {
       sl=sl+(l-1)*l/2;
       l=1;
   }
    sl=sl+(l-1)*l/2;
   printf("%d\n",sl);
    return 0;
}