Pagini recente » Cod sursa (job #1773102) | Cod sursa (job #355679) | Cod sursa (job #1283269) | Cod sursa (job #89085) | Cod sursa (job #1148570)
#include<iostream>
using namespace std;
struct dreptunghi
{
int x1;
int y1;
int x2;
int y2;
};
long long perimetru(dreptunghi a)
{
int lungime = abs(a.x2 - a.x1);
int latime = abs(a.y2 - a.y1);
return lungime * 2 + latime * 2;
}
long long arie(dreptunghi a)
{
int lungime = abs(a.x2 - a.x1);
int latime = abs(a.y2 - a.y1);
return lungime * latime;
}
dreptunghi reuniune(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.x2 < c.x1 || c.y2 < c.y1)
c.x1 = c.x2 = c.y1 = c.y2 = 0;
return c;
}
int main()
{
freopen("reuniune.in", "r", stdin);
freopen("reuniune.out", "w", stdout);
dreptunghi a, b, c;
scanf("%d%d%d%d", &a.x1, &a.y1, &a.x2, &a.y2);
scanf("%d%d%d%d", &b.x1, &b.y1, &b.x2, &b.y2);
scanf("%d%d%d%d", &c.x1, &c.y1, &c.x2, &c.y2);
dreptunghi reuniune_totala = reuniune(reuniune(a, b), c);
long long arie_totala = arie(a) + arie(b) + arie(c) - arie(reuniune(a, b)) - arie(reuniune(b, c)) - arie(reuniune(a, c)) + arie(reuniune_totala);
long long perimetru_total = perimetru(a) + perimetru(b) + perimetru(c) - perimetru(reuniune(a, b)) - perimetru(reuniune(b, c)) - perimetru(reuniune(a, c)) + perimetru(reuniune_totala);
printf("%lld %lld\n", arie_totala, perimetru_total);
return 0;
}