Cod sursa(job #1330521)

Utilizator bogdan10bosBogdan Sitaru bogdan10bos Data 30 ianuarie 2015 19:11:09
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.41 kb
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>

#define INF (1<<30)
#define mod 666013

using namespace std;
typedef long long LL;
struct punct
{
    LL x, y;
}x, y;
struct dreptunghi
{
    punct a, b;
}a, b, c, ab, bc, ac, abc;
LL arie, perimetru;
dreptunghi I(dreptunghi a, dreptunghi b)
{
    dreptunghi r;
    punct x, y;
    x.x=max(a.a.x, b.a.x);
    x.y=max(a.a.y, b.a.y);
    y.x=min(a.b.x, b.b.x);
    y.y=min(a.b.y, b.b.y);
    r.a=x;
    r.b=y;
    return r;
}
LL P(dreptunghi a)
{
    if(a.a.x>a.b.x) return 0;
    if(a.a.y>a.b.y) return 0;
    return ((a.b.x-a.a.x+a.b.y-a.a.y)<<1);
}
LL A(dreptunghi a)
{
    if(a.a.x>a.b.x) return 0;
    if(a.a.y>a.b.y) return 0;
    return ((a.b.x-a.a.x)*(a.b.y-a.a.y));
}
int main()
{
    freopen("reuniune.in", "r", stdin);
    freopen("reuniune.out", "w", stdout);

    scanf("%lld%lld%lld%lld", &x.x, &x.y, &y.x, &y.y);
    a.a=x;a.b=y;
    scanf("%lld%lld%lld%lld", &x.x, &x.y, &y.x, &y.y);
    b.a=x;b.b=y;
    scanf("%lld%lld%lld%lld", &x.x, &x.y, &y.x, &y.y);
    c.a=x;c.b=y;
    ab=I(a, b);
    ac=I(a, c);
    bc=I(b, c);
    abc=I(ab, c);
    arie=A(a)+A(b)+A(c)-A(ab)-A(bc)-A(ac)+A(abc);
    perimetru=P(a)+P(b)+P(c)-P(ab)-P(bc)-P(ac)+P(abc);
    printf("%lld %lld", arie, perimetru);
    return 0;
}