Cod sursa(job #1223714)

Utilizator killer301Ioan Andrei Nicolae killer301 Data 28 august 2014 17:33:49
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <cstdio>
#include <algorithm>

using namespace std;

struct drept
{
    long long x1, y1, x2, y2;
};
drept a, b, c;

long long arie(drept d)
{
    return ((d.x2-d.x1)*(d.y2-d.y1));
}
long long perimetru(drept d)
{
    return (2*((d.x2-d.x1)+(d.y2-d.y1)));
}

drept inter(drept d1, drept d2)
{
    drept d;
    d.x1=max(d1.x1, d2.x1);
    d.y1=max(d1.y1, d2.y1);
    d.x2=min(d1.x2, d2.x2);
    d.y2=min(d1.y2, d2.y2);
    if(d.x1>d.x2 || d.y1>d.y2)
        d.x1=d.x2=d.y1=d.y2=0;
    return d;
}

int main()
{
	freopen("reuniune.in", "r", stdin);
	freopen("reuniune.out", "w", stdout);
    long long ar, p;
    scanf("%lld%lld%lld%lld", &a.x1, &a.y1, &a.x2, &a.y2);
    scanf("%lld%lld%lld%lld", &b.x1, &b.y1, &b.x2, &b.y2);
    scanf("%lld%lld%lld%lld", &c.x1, &c.y1, &c.x2, &c.y2);
    ar=arie(a)+arie(b)+arie(c)-arie(inter(a, b))-arie(inter(a, c))-arie(inter(b, c))+arie(inter(a, (inter(b, c))));
    p=perimetru(a)+perimetru(b)+perimetru(c)-perimetru(inter(a, b))-perimetru(inter(a, c))-perimetru(inter(b, c))+perimetru(inter(a, (inter(b, c))));
    printf("%lld %lld", ar, p);
    return 0;
}