Cod sursa(job #2659048)

Utilizator filip_as@Cirtog Filip Andrei filip_as@ Data 15 octombrie 2020 18:22:34
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

const double PI=2.0*acos(0);
const double eps=1.0e-14;
const double INF=2.0e9;
double panta[600001];
int n;
class POINT
{
public:
    double x,y;
    POINT()
    {
        x=y=0;
    }
    POINT(double x0, double y0)
    {
        x=x0;
        y=y0;
    }
    POINT(const POINT&other)
    {
        x=other.x;
        y=other.y;
    }
    void setxy(double x0, double y0)
    {
        x=x0;
        y=y0;
    }
    double pant_calc(const POINT&other)
    {
        if (fabs(other.x - x) < eps)
            return INF;
        return (other.y - y) / (other.x - x);
    }

};
POINT p[1001];
int nr=0;
void citire()
{
    int  i, j,x,y;
    scanf("%d",&n);
    for (i = 0; i < n; i++)
    {
        scanf("%d%d",&x,&y);
        p[i].setxy(x, y);
    }
}
void solutie()
{
    int i,j,k=0,cnt=1;
    for(i =0; i < n - 1; i++)
        for(j = i + 1; j < n; j++)
                panta[k++] = p[i].pant_calc(p[j]);
    sort(panta, panta + k);
    for(i = 1; i <= k; i++)
    {


        if(panta[i] == panta[i - 1])
            cnt++;
        else
        {
            nr += (cnt * (cnt - 1)) / 2;
            cnt = 1;
        }
    }
    nr += (cnt * (cnt - 1)) / 2;
}
void afisare()
{
     printf("%d",nr);
}
int main()
{
    freopen("trapez.in","r",stdin);
     freopen("trapez.out","w",stdout);
    citire();
    solutie();
    afisare();
    return 0;
}