Cod sursa(job #2658602)

Utilizator chiravladChira Vlad chiravlad Data 14 octombrie 2020 15:42:22
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const double eps = 1.0e-14;
const double INF = 2.0e+9;

class POINT
{
private:
    int x,y;
public:
    POINT()
    {
        x = y = 0;
    }

    POINT(int x0, int y0)
    {
        x = x0;
        y = y0;
    }

    void setxy(int x0, int y0)
    {
        x = x0;
        y = y0;
    }

    int getx()
    {
        return x;
    }
    int gety()
    {
        return y;
    }

    double panta(const POINT &other)
    {
        if(fabs(other.x-x) < eps)
            return INF;
        return ((1.0 * other.y-y) / (1.0 *other.x-x));
    }

};

vector<POINT> points;
vector<double> slopes;

int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,tempx,tempy;
    scanf("%d",&n);
    for(int i = 1; i<=n; i++)
    {
        scanf("%d%d",&tempx,&tempy);
        POINT temp(tempx,tempy);
        points.push_back(temp);
    }

    vector<POINT>::iterator it,it2;
    for(it = points.begin(); it != points.end(); it++)
        for(it2 = it + 1; it2 != points.end(); it2++)
        {
            double _panta = (*it).panta((*it2));
            slopes.push_back(_panta);
        }
    std::sort(slopes.begin(),slopes.end());
    long long l=1;
    long long tr=0;
    for(int i = 0; i < slopes.size(); i++)
    {
        if(slopes[i]==slopes[i-1])
            l++;
        else
        {
            tr+=l*(l-1)/2;
            l=1;
        }
    }
    tr+=l*(l-1)/2;
    printf("%lld",tr);
    return 0;
}