Cod sursa(job #2877614)

Utilizator AswVwsACamburu Luca AswVwsA Data 25 martie 2022 00:43:59
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.7 kb
#include <fstream>
#include <algorithm>
#include <stack>
#define int long long
using namespace std;
struct drept
{
    int x0, y0, x1, y1;
    int arie()
    {
        return (x1 - x0) * (y1 - y0);
    }
    int peri()
    {
        return 2 * (x1 - x0 + y1 - y0);
    }
    bool check()
    {
        return !(x0 == x1
                 and x1 == y1
                 and y1 == y0
                 and y0 == 0);
    }
};

drept in2(drept a, drept b)
{
    drept ans;
    int mny = max(a.y0, b.y0);
    if (mny > a.y1)
    {
        ans.x0 = ans.x1 = ans.y1 = ans.y0 = 0;
        return ans;
    }
    int mnx = max(a.x0, b.x0);
    if (mnx > a.x1)
    {
        ans.x0 = ans.x1 = ans.y1 = ans.y0 = 0;
        return ans;
    }
    int mxx = min(a.x1, b.x1);
    int mxy = min(a.y1, b.y1);
    ans.x0 = mnx;
    ans.y0 = mny;
    ans.x1 = mxx;
    ans.y1 = mxy;
    return ans;
}

drept in3(drept a, drept b, drept c)
{
    drept ans = in2(a, b);
    if (!ans.check())
    {
        ans.x0 = ans.x1 = ans.y1 = ans.y0 = 0;
        return ans;
    }
    ans = in2(ans, c);
    if (!ans.check())
        ans.x0 = ans.x1 = ans.y1 = ans.y0 = 0;
    return ans;
}
signed main()
{
    ifstream cin("reuniune.in");
    ofstream cout("reuniune.out");
    drept a, b, c;
    cin >> a.x0 >> a.y0 >> a.x1 >> a.y1;
    cin >> b.x0 >> b.y0 >> b.x1 >> b.y1;
    cin >> c.x0 >> c.y0 >> c.x1 >> c.y1;
    cout << a.arie() + b.arie() + c.arie() - in2(a, b).arie()
            - in2(a, c).arie() - in2(b, c).arie() + in3(a, b, c).arie()
        << " ";
    cout << a.peri() + b.peri() + c.peri() - in2(a, b).peri()
            - in2(a, c).peri() - in2(b, c).peri() + in3(a, b, c).peri();
}