Cod sursa(job #2624228)

Utilizator Robert.BrindeaBrindea Robert Robert.Brindea Data 4 iunie 2020 16:59:44
Problema Reuniune Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.05 kb
#include <iostream>
#include <fstream>

using namespace std;

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

struct Colt
{
    int x, y;
    Colt(int xx=0, int yy=0)
    {
        x = xx;
        y = yy;
    }
};

struct Dreptunghi
{
    Colt jos, sus;
    int lorizontala, lverticala;
    Dreptunghi(int x1=0, int y1=0, int x2=0, int y2=0)
    {
        jos = Colt(x1, y1);
        sus = Colt(x2, y2);
        update();
    }
    Dreptunghi operator+(const Dreptunghi &d1)
    {
        Dreptunghi res = Dreptunghi(max(jos.x, d1.jos.x), max(jos.y, d1.jos.y), min(sus.x, d1.sus.x), min(sus.y, d1.sus.y));
        if(res.jos.x > res.sus.x || res.jos.y > res.sus.y)
            return 0;
        return res;
    }
    void operator+=(const Dreptunghi &d1)
    {
        if(sus.x == 0 && sus.y == 0 && jos.x == 0 && jos.y == 0)
        {
            *this = d1;
            return;
        }
        *this = *this + d1;
    }
    void update()
    {
        lorizontala = sus.x - jos.x;
        lverticala = sus.y - jos.y;
    }
    void print()
    {
        cout << jos.x << " " << jos.y << "   " << sus.x << " " << sus.y << " - ";
    }
};

long long arie(const Dreptunghi &d)
{
    return 1LL * d.lorizontala * d.lverticala;
}

long long perimetru(const Dreptunghi &d)
{
    return 1LL * 2 * d.lorizontala + 2 * d.lverticala;
}

Dreptunghi d[4];

long long solve(long long funct(const Dreptunghi&))
{
    long long res = 0;
    for(int i = 1; i < 8; i++)
    {
        Dreptunghi curr = Dreptunghi(0, 0, 0, 0);
        int sign = -1;
        for(int j = 0; i >> j; j++)
        {
            if( (i>>j) & 1)
                curr += d[j], sign *= -1;
        }
        curr.update();
        res += sign*funct(curr);
    }
    return res;
}

int main()
{
    for(int i = 0; i < 3; i++)
    {
        int x1, x2, y1, y2;
        fin >> x1 >> y1 >> x2 >> y2;
        d[i] = Dreptunghi(x1, y1, x2, y2);
    }
    fout << solve(arie) << " ";
    fout << solve(perimetru);
    return 0;
}