Cod sursa(job #3125366)

Utilizator andreea0146Nicula Andreea andreea0146 Data 2 mai 2023 20:45:24
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
struct dreptunghi
{
    long long x1, y1, x2, y2;
} v[3];
long long arie(dreptunghi a)
{
    return (a.x1 - a.x2) * (a.y1 - a.y2);
}
long long perimetru(dreptunghi a)
{
    return 2 * (a.x2 - a.x1 + a.y2 - a.y1);
}
dreptunghi intersectate(dreptunghi a, dreptunghi b)
{
    dreptunghi c;
    c.x1 = max(a.x1, b.x1);
    c.y1 = max(a.y1, b.y1);
    c.x2 = min(a.x2, b.x2);
    c.y2 = min(a.y2, b.y2);
    if(c.x1 <= c.x2 and c.y1 <= c.y2) return c;
    else
    {
        c.x1=c.x2=c.y1=c.y2=0;
        return c;
    }
}
int main()
{
    for(int i = 0; i <= 2; ++i)
        fin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
    fout<<arie(v[0])+arie(v[1])+arie(v[2])-arie(intersectate(v[0],v[1]))-arie(intersectate(v[1],v[2]))-arie(intersectate(v[2],v[0]))+arie(intersectate(v[0], intersectate(v[1], v[2])));
    fout << ' ';
    fout << perimetru(v[0])+perimetru(v[1]) + perimetru(v[2]) - perimetru(intersectate(v[0], v[1])) - perimetru(intersectate(v[1], v[2])) - perimetru(intersectate(v[2], v[0])) + perimetru(intersectate(v[0], intersectate(v[1], v[2])));
    return 0;
}