Cod sursa(job #2237603)

Utilizator CristeaCristianCristea Cristian CristeaCristian Data 2 septembrie 2018 13:43:57
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 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;
}