Cod sursa(job #2658960)

Utilizator Moroianu_Adrian_StefanMoroianu Adrian Stefan Moroianu_Adrian_Stefan Data 15 octombrie 2020 16:41:08
Problema Trapez Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
const double INF=2.0e9;
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;
        }
        friend double panta(POINT a,POINT b)
        {
            if(fabs(a.x-b.x)==0)
                return INF;
            return (1.0*(b.y-a.y))/(1.0*(b.x-a.x));
        }
};
ifstream fin("trapez.in");
ofstream fout("trapez.out");
vector<POINT>v;
vector<double>p;
int main()
{
    int n,i,x0,y0,j,k=0;
    double m;
    POINT temp;
    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>x0>>y0;
        temp.setxy(x0,y0);
        v.push_back(temp);
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
            {
                m=panta(v[i],v[j]);
                p.push_back(m);
            }
    }
    sort(p.begin(),p.end());
    for(i=0;i<p.size()-1;i++)
        if(p[i]==p[i+1])
            k++;
    fout<<k;
    return 0;
}