Cod sursa(job #3217736)

Utilizator vladdobro07vladdd vladdobro07 Data 24 martie 2024 14:52:47
Problema Reuniune Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct dreptung {
        ll x1, x2, y1, y2;

        dreptung(ll x, ll y, ll X, ll Y) {
                x1 = x;
                x2 = X;
                y1 = y;
                y2 = Y;
        }

        dreptung() {};

        ll perimetru() {
                return 2 * ((x2 - x1) + (y2 - y1));
        }

        ll arie() {
                return (x2 - x1) * (y2 - y1);
        }

        dreptung operator &(dreptung other) {
                dreptung rez;
                rez.x1 = max(x1, other.x1);
                rez.x2 = min(x2, other.x2);
                rez.y1 = max(y1, other.y1);
                rez.y2 = min(y2, other.y2);
                if(x2 < x1 || y2 < y1)
                        return dreptung(0, 0, 0, 0);
                return rez;
        }
};

signed main() {
        dreptung a, b, c;
        cin >> a.x1 >> a.y1 >> a.x2 >> a.y2 >> b.x1 >> b.y1 >> b.x2 >> b.y2 >> c.x1 >> c.y1 >> c.x2 >> c.y2;
        cout << a.arie() + b.arie() + c.arie() - (a & b).arie() - (c & b).arie() - (a & c).arie() + ((a & b) & c).arie() << " ";
        cout << a.perimetru() + b.perimetru() + c.perimetru() - (a & b).perimetru() - (c & b).perimetru() - (a & c).perimetru() + ((a & b) & c).perimetru() << " ";
        return 0;
}