Cod sursa(job #2606242)

Utilizator REDCRAFTPadure Damian REDCRAFT Data 27 aprilie 2020 12:58:30
Problema Trapez Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 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 dist(POINT P1, POINT P2)
{
    return sqrt((P2.x-P1.x)*(P2.x-P1.x)+(P2.y-P1.y)*(P2.y-P1.y));
}
bool same_point(POINT P1, POINT P2)
{
    if(fabs(P1.x-P2.x)<eps&&fabs(P1.y-P2.y)<eps)
        return 1;
    return 0;
}
POINT medium_point(POINT P1,POINT P2)
{
    POINT M;
    M.x=(P1.x+P2.x)*0.5;
    M.y=(P1.y+P2.y)*0.5;
    return M;
}
bool horizontal(POINT P1, POINT P2)
{
    return fabs(P1.y-P2.y)<eps;
}
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[505];

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;
}