Cod sursa(job #2237745)

Utilizator AlexandraCristeaAlexandraCristea AlexandraCristea Data 2 septembrie 2018 22:34:21
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps=1.0e-14;
const double INF=2000000000;
struct point
{
    int x,y;
};
double panta(point p1,point p2)
{
    if(fabs (p2.x-p1.x)<eps)
    return INF;
    return (double)(p2.y-p1.y)/(p2.x-p1.x);
}
point p[1005];
double v[1000005];
int main()
{
    freopen("trapez.in","r",stdin);
    freopen ("trapez.out","w",stdout);
    int n,i,m=0,l=1,j,nr=0;
    scanf ("%d",&n);
    for (i=1;i<=n;i++)
        scanf ("%d%d",p[i].x,&p[i].y);
    for (i=1;i<n;i++)
    {
        for(j=i+1; j<=n; j++)
        {
            m++;
            v[m]=panta(p[i],p[j]);
        }
    }
    sort(v+1,v+m+1);
    for(i=2; i<=m; i++)
    {
        if(fabs(v[i]-v[i-1])<eps)
           l++;
           else
           {
            nr=nr+(l*(l-1))/2;
            l=1;
           }
    }
    printf("%d",nr);
    return 0;
}