Cod sursa(job #2237460)

Utilizator HoriqHoria Pacurar Horiq Data 1 septembrie 2018 22:40:50
Problema Trapez Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
const double eps=10e-14;
const double INF=2000000000;
struct POINT
{
    int x,y;
};
double panta(POINT A,POINT B)
{
    if(fabs(B.x-A.x)<eps)
        return INF;
    else
    return (double)(B.y-A.y)/(B.x-A.x);
}
POINT P[1001];
double v[100002];
int main()
{
    int n,l=0,i,j,sortat,k=1,s=0;
    double aux;
    fin>>n;
    for(i=1;i<=n;i++)
        fin>>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(fabs(v[i]-v[i+1])<eps)
                k++;
            else
            {
                s=s+(k*(k-1))/2;
                k=1;
            }
        }
    fout<<s;
    return 0;
}