Cod sursa(job #2606244)

Utilizator REDCRAFTPadure Damian REDCRAFT Data 27 aprilie 2020 13:00:02
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

const double eps=1.0e-14;
const double INF=2.0e+9;
struct POINT
{
    int x,y;
};
double panta(POINT P1, POINT P2)
{
    if(fabs(P1.x-P2.x)<eps)
        return INF;
    else
        return (1.0*P2.y-P1.y)/(1.0*P2.x-P1.x);
}

POINT pts[1005];
double p[499505];

int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,i,k=0,cnt,nrp=0,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&pts[i].x,&pts[i].y);
    }
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
        {
            p[++k]=panta(pts[i],pts[j]);
        }
    sort(p+1,p+k);
    cnt=0;
    for(i=1;i<=k;i++)
    {
        if(p[i]-p[i+1]>=-eps&&p[i]-p[i+1]<=eps)
            cnt++;
        else
        {
            nrp+=cnt*(cnt+1)/2;
            cnt=0;
        }
    }
    printf("%d",nrp);
    return 0;
}