Cod sursa(job #2658959)

Utilizator InfoFabianaFabiana Maria InfoFabiana Data 15 octombrie 2020 16:38:50
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.32 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;

int x[1001], y[1001];

ifstream fin("trapez.in");
ofstream fout("trapez.out");

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 getx()
    {
        return x;
    }
    double gety()
    {
        return y;
    }
    double dist(const POINT&other)
    {
        return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y));
    }

};

class PATRULATER
{
private:
    POINT a, b, c, d;
public:
    float l[4];
    float diag1, diag2;
    PATRULATER(POINT a0, POINT b0, POINT c0, POINT d0)
    {
        a = a0;
        b = b0;
        c = c0;
        d = d0;
    }
    int verificaretrapez()
    {
        int mab, mbc, mcd, mda;
        mab = (b.y - a.y) / (b.x - a.x);
        mbc = (c.y - b.y) / (c.x - b.x);
        mcd = (d.y - c.y) / (d.x - c.x);
        mda = (d.y - a.y) / (d.x - a.x);
        if ((mab == mbc && mcd != mda) || (mab == mcd && mbc != mda) || (mab == mda && mbc != mcd) || (mbc == mcd && mab != mda) || (mbc == mda && mab != mcd) || (mcd == mda && mab != mbc))
            return 1;
        return 0;
    }
};

int main()
{
    int n, i, nr = 0, i2, i3, i4;
    fin>>n;
    POINT a(0,0);
    POINT b(0, 0);
    POINT c(0,0);
    POINT d(0, 0);
    for (i = 1; i <= n; i++)
    {
        fin>>x[i]>>y[i];
    }
    for (i = 1; i <= n; i++)
    {
        for (i2 = i + 1; i2 <= n; i2++)
        {
            for (i3 = i2 + 1; i3 <= n; i3++)
            {
                for (i4 = i3 + 1; i4 <= n; i4++)
                {
                    a.setxy(x[i], y[i]);
                    b.setxy(x[i2], y[i2]);
                    c.setxy(x[i3], y[i3]);
                    d.setxy(x[i4], y[i4]);
                    PATRULATER p1(a, b, c, d);
                    if (p1.verificaretrapez())
                        nr++;
                }
            }
        }
    }
    fout<<nr;
    return 0;
}