Cod sursa(job #2237442)

Utilizator HoriqHoria Pacurar Horiq Data 1 septembrie 2018 21:13:48
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <cmath>
using namespace std;

const double eps=10e-6;
const double INF=2000000000;
struct POINT
{
    double x,y;
};
double panta(POINT A,POINT B)
{
    if(fabs(B.x-A.x)<eps)
        return INF;
    else
    return (B.y-A.y)/(B.x-A.x);
}
POINT P[1001];
double v[100002];
int main()
{
    int n,l=0,i,j,sortat,k=0;
    double aux;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>P[i].x>>P[i].y;
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
        {
            l++;
            v[l]=panta(P[i],P[j]);
        }
    do
    {
        sortat=1;
        for(i=1;i<l;i++)
            if(v[i]>v[i+1])
        {
            aux=v[i];
            v[i]=v[i+1];
            v[i+1]=aux;
            sortat=0;
        }
    }while(sortat==0);
    for(i=1;i<=l;i++)
        if(v[i]==v[i+1])
            k++;
    cout<<k;
    return 0;
}