Cod sursa(job #1383830)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 10 martie 2015 18:07:59
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.41 kb
#include <cstdio>
#include <climits>
#include <algorithm>

#define ll long long

#define x first.first
#define y first.second
#define X second.first
#define Y second.second

#define A first
#define P second

using namespace std;

ll nr_inter , nou_x , nou_y , nou_X , nou_Y;
pair < ll , ll > inter[4];

ll i , j , v;
pair < pair < ll , ll > , pair < ll , ll > > a[4];

int main()
{
    freopen("reuniune.in","r",stdin);
    freopen("reuniune.out","w",stdout);

    for (i = 1; i <= 3; ++i)
        scanf("%lld %lld %lld %lld", &a[i].x, &a[i].y, &a[i].X, &a[i].Y);

    for (i = 1; i < 8; ++i)
    {
        nou_x = nou_y = LONG_MIN; nou_X = nou_Y = LONG_MAX;

        for (v = i , nr_inter = 0 , j = 1; j <= 3; ++j , v >>= 1)
            if (v & 1)
            {
                nr_inter++;
                nou_x = max(nou_x , a[j].x);
                nou_y = max(nou_y , a[j].y);
                nou_X = min(nou_X , a[j].X);
                nou_Y = min(nou_Y , a[j].Y);
            }

        if (nou_X >= nou_x && nou_Y >= nou_y)
        {
            inter[nr_inter].A += (nou_X - nou_x) * (nou_Y - nou_y);
            inter[nr_inter].P += 2 * (nou_X - nou_x) + 2 * (nou_Y - nou_y);
        }
    }

    inter[0].A = inter[1].A - inter[2].A + inter[3].A;
    inter[0].P = inter[1].P - inter[2].P + inter[3].P;

    printf("%lld %lld\n" , inter[0].A , inter[0].P);

    return 0;
}