Cod sursa(job #2745198)

Utilizator cyg_alexandru546Zob Alexandru Mihai cyg_alexandru546 Data 25 aprilie 2021 23:55:55
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.08 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

const double eps = 1.0e-14;
const double INF = 1e9;

ifstream cin("trapez.in");
ofstream cout("trapez.out");

class POINT
{
private:
    double x,y;
public:
    //Constuctori
    POINT()
    {
        x = y = 0;
    }
    POINT(double _x, double _y)
    {
        x = _x;
        y = _y;
    }
    POINT(const POINT &other)
    {
        x = other.x;
        y = other.y;
    }
    int getx()
    {
        return x;
    }
    int gety()
    {
        return y;
    }
    void setxy(double _x, double _y)
    {
        x = _x;
        y = _y;
    }
    double dist(const POINT &other)
    {
        return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y));
    }
    POINT mijloc(const POINT &other)
    {
        POINT temp;
        temp.x = (x+other.x)*0.5;
        temp.y = (y+other.y)*0.5;
        return temp;
    }
    double panta(const POINT &other)
    {
        if(fabs(x-other.x)<eps)
            return INF;
        return (y-other.y)/(x-other.x);
    }
    bool operator ==(const POINT &other)
    {
        return (fabs(x-other.x)<eps) && (fabs(y-other.y)<eps);
    }
    bool operator <(const POINT &other)
    {
        if(fabs(x-other.x)>eps)
            return x<other.x;
        return y<other.y;
    }
};//final clasa

int main()
{
    int n,i,tx,ty,j,trapeze = 0,cnt;
    vector<POINT> v;
    vector<double> p;
    POINT temp;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> tx >> ty;
        temp.setxy(tx,ty);
        v.push_back(temp);
    }
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
        {
            p.push_back(v[i].panta(v[j]));
        }
    sort(p.begin(),p.end());
    cnt = 1;
    for(i=1;i<p.size();i++)
    {
        if(fabs(p[i]-p[i-1])<eps)
        {
            cnt++;
            continue;
        }
        else
        {
            if(cnt>1)
                trapeze+=cnt*(cnt-1)/2;
            cnt=1;
        }
    }
    cout << trapeze;
    return 0;
}