Cod sursa(job #1435829)

Utilizator lucaignatescuIgnatescu Luca lucaignatescu Data 14 mai 2015 17:52:55
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
#define eps 1.e-14
#define INF 1.e+12

using namespace std;

struct POINT
{
  int x,y;
};

POINT v[1005];
double p[550000];

bool vertical(POINT A,POINT B)
{
  return A.x==B.x;
}
double panta(POINT a,POINT b)
{
    if(vertical(a,b))
       return INF;
    else
       return ((double)b.y-a.y)/(b.x-a.x);
}
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,i,j,k,a,b,l;
    long long s=0;
    scanf("%d",&n);
    for(i=1;i<=n;++i)
    {
      scanf("%d%d",&a,&b);
      v[i].x=a;
      v[i].y=b;
    }
     k=0;
     for(i=1;i<n;++i)
         for(j=i+1;j<=n;++j)
             p[++k]=panta(v[i],v[j]);
    sort(p+1,p+k+1);
    l=1;
    for(i = 2; i<= k; ++i)
        if(fabs(p[i-1] - p[i])<eps)
          ++l;
    else{
      s=s+(long long)l*(l-1)/2;
      l=1;
    }
    s=s+(long long)l*(l-1)/2;
    printf("%I64d\n",s);
    return 0;
}