Cod sursa(job #2221316)

Utilizator tudorbuhniaTudor Buhnia tudorbuhnia Data 13 iulie 2018 18:08:28
Problema Trapez Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.79 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const double INF=1e9;
const double eps=1.e-14;
struct pt
{
    int x,y;
}v[1005];
class POINT
{
    private:
        short x,y;
    public:
    POINT()
    {
        x=0;
        y=0;
    }
    POINT(short _x,short _y)
    {
        x=_x;
        y=_y;
    }
    POINT(const POINT & other)
    {
        x=other.x;
        y=other.y;
    }
    double dist(const POINT & other)
    {
        return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y));
    }
    double panta(const POINT & other)
    {
        if(fabs(x-other.x)<eps)
            return INF;
        return 1.0*(y-other.y)/(x-other.x);
    }
    void set(double x1,double y1)
    {
        x=x1;
        y=y1;
    }
    double getx()
    {
        return x;
    }
    double gety()
    {
        return y;
    }
};
vector<double> pv;
int main()
{
    ifstream cin("trapez.in");
    ofstream cout("trapez.out");
    POINT a;
    POINT b;
    int n,x1,y1,x2,y2,cnt=0,cx=0;
    long long int s=0;
    double pt,p;
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> v[i].x >> v[i].y;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            cnt++;
            x1=v[i].x;
            y1=v[i].y;
            x2=v[j].x;
            y2=v[j].y;
            a.set(x1,y1);
            b.set(x2,y2);
            pt=a.panta(b);
            pv.push_back(pt);
        }
    }
    sort(pv.begin(),pv.end());
    p=pv[0];
    for(int i=0;i<cnt;i++)
    {
        if(pv[i]==p)
            cx++;
        else
        {
            s+=(cx*(cx-1)/2);
            cx=1;
            p=pv[i];
        }
    }
    s+=(cx*(cx-1)/2);
    cout << s;
    return 0;
}