Cod sursa(job #2237461)

Utilizator HoriqHoria Pacurar Horiq Data 1 septembrie 2018 22:43:42
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double INF=2000000000;
const double eps=1.0e-14;
struct POINT
{
    int x,y;
};
double panta1(POINT P1,POINT P2)
{
    if(fabs(P2.x-P1.x)<eps)
        return INF;
    return (double)(P2.y-P1.y)/(P2.x-P1.x);
}
POINT v[1005];
double panta[1000005];
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,i,k=1,l=0,j,s=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d%d",&v[i].x,&v[i].y);
    for(i=1;i<n;i++)
    {
        for(j=i+1;j<=n;j++)
            panta[++l]=panta1(v[i],v[j]);
    }
    sort(panta+1,panta+l+1);
    for(i=2;i<=l;i++)
    {
        if(fabs(panta[i]-panta[i-1])<eps)
            k++;
        else
        {
            s=s+(k*(k-1))/2;
            k=1;
        }
    }
    printf("%d",s);
    return 0;
}