Cod sursa(job #1223642)

Utilizator A63N7pTudor Nazarie A63N7p Data 28 august 2014 14:41:20
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.3 kb
#include <cassert>
#include <cstdio>

long long x11 = 0, x12 = 0, y11 = 0, y12 = 0, x21 = 0, x22 = 0, y21 = 0, y22 = 0, x31 = 0, x32 = 0, y31 = 0, y32 = 0;
long long abx1 = 0, abx2 = 0, aby1 = 0, aby2 = 0, acx1 = 0, acx2 = 0, acy1 = 0, acy2 = 0, bcy1 = 0, bcy2 = 0, bcx1 = 0, bcx2 = 0, abcx1 = 0, abcx2 = 0, abcy1 = 0, abcy2 = 0;

inline int max(int, int);
inline int min(int, int);

inline void ab();
inline void ac();
inline void bc();
inline void abc();

int main(int argc, char *argv[])
{
    freopen("reuniune.in", "r", stdin);
    freopen("reuniune.out", "w", stdout);

    long long a, p;

    scanf("%lld %lld %lld %lld", &x11, &y11, &x12, &y12);
    scanf("%lld %lld %lld %lld", &x21, &y21, &x22, &y22);
    scanf("%lld %lld %lld %lld", &x31, &y31, &x32, &y32);

    abc();

    a = (x12 - x11) * (y12 - y11) + (x22 - x21) * (y22 - y21) + (x32 - x31) * (y32 - y31) + (abcx2 - abcx1) * (abcy2 - abcy1);
    a -=((abx2 - abx1) * (aby2 - aby1) + (acx2 - acx1) * (acy2 - acy1) + (bcx2 - bcx1) * (bcy2 - bcy1));

    p = x12 + y12 + x22 + y22 + x32 + y32 + abx1 + aby1 + acx1 + acy1 + bcx1 + bcy1 + abcx2 + abcy2;
    p -= (x11 + y11 + x21 + y21 + x31 + y31 + abx2 + aby2 + acx2 + acy2 + bcx2 + bcy2 + abcx1 + abcy1);
    p *= 2;

    printf("%lld %lld\n", a, p);

    return 0;
}

inline int max(int a, int b)
{
    return a > b ? a : b;
}

inline int min(int a, int b)
{
    return a < b ? a : b;
}

inline void ab()
{
    abx1 = max(x11, x21);
    abx2 = min(x12, x22);
    aby1 = max(y11, y21);
    aby2 = min(y12, y22);
}

inline void ac()
{
    acx1 = max(x11, x31);
    acx2 = min(x12, x32);
    acy1 = max(y11, y31);
    acy2 = min(y12, y32);
}

inline void bc()
{
    bcx1 = max(x21, x31);
    bcx2 = min(x22, x32);
    bcy1 = max(y21, y31);
    bcy2 = min(y22, y32);
}

inline void abc()
{
    ab();
    ac();
    bc();

    if (abx1 > abx2 || aby1 > aby2)
        abx1 = abx2 = aby1 = aby2 = 0;
    if (acx1 > acx2 || acy1 > acy2)
        acx1 = acx2 = acy1 = acy2 = 0;
    if (bcx1 > bcx2 || bcy1 > bcy2)
        bcx1 = bcx2 = bcy1 = bcy2 = 0;

    abcx1 = max(abx1, x31);
    abcx2 = min(abx2, x32);
    abcy1 = max(aby1, y31);
    abcy2 = min(aby2, y32);

    if (abcx1 > abcx2 || abcy1 > abcy2)
        abcx1 = abcx2 = abcy1 = abcy2 = 0;
}