Cod sursa(job #1523855)

Utilizator DeehoroEjkoliPop Darian DeehoroEjkoli Data 13 noiembrie 2015 13:33:07
Problema Reuniune Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.59 kb
#include <fstream>
#include <cmath>
#include <iostream>
using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");

long long xOne0, yOne0, xOne1, yOne1;
long long xTwo0, yTwo0, xTwo1, yTwo1;
long long xThree0, yThree0, xThree1, yThree1;

long long maximum(long long a, long long b, long long c) {
    return max(max(a, b), c);
}

long long minimum(long long a, long long b, long long c) {
    return min(min(a, b), c);
}

void reading() {
    fin >> xOne0 >> yOne0 >> xOne1 >> yOne1;
    fin >> xTwo0 >> yTwo0 >> xTwo1 >> yTwo1;
    fin >> xThree0 >> yThree0 >> xThree1 >> yThree1;
}

int main()
{
    reading();
    long long reunionX, reunionY;
    reunionX = minimum(xOne1, xTwo1, xThree1) - maximum(xOne0, xTwo0, xThree0);
    if (reunionX < 0)
        reunionX = 0;
    reunionY = minimum(yOne1, yTwo1, yThree1) - maximum(yOne0, yTwo0, yThree0);
    if (reunionY < 0)
        reunionY = 0;
    long long arieABC, arieAB, arieBC, arieAC;
    arieABC = reunionX * reunionY;
    long long reunionXab, reunionXbc, reunionXac, reunionYab, reunionYbc, reunionYac;

    reunionXab = min(xOne1, xTwo1) - max(xOne0, xTwo0);
    if (reunionXab < 0)
        reunionXab = 0;
    reunionYab = min(yOne1, yTwo1) - max(yOne0, yTwo0);
    if (reunionYab < 0)
        reunionYab = 0;
    arieAB = reunionXab * reunionYab;

    reunionXbc = min(xTwo1, xThree1) - max(xTwo0, xThree0);
    if (reunionXbc < 0)
        reunionXbc = 0;
    reunionYbc = min(yTwo1, yThree1) - max(yTwo0, yThree0);
    if (reunionYbc < 0)
        reunionYbc = 0;
    arieBC = reunionXbc * reunionYbc;

    reunionXac = min(xOne1, xThree1) - max(xOne0, xThree0);
    if (reunionXac < 0)
        reunionXac = 0;
    reunionYac = min(yOne1, yThree1) - max(yOne0, yThree0);
    if (reunionYac < 0)
        reunionYac = 0;
    arieAC = reunionXac * reunionYac;
    long long totalArea;
    totalArea = (xOne1 - xOne0) * (yOne1 - yOne0) + (xTwo1 - xTwo0) * (yTwo1 - yTwo0) + (xThree1 - xThree0) * (yThree1 - yThree0);
    fout << totalArea - arieAB - arieAC - arieBC + arieABC << " ";

    long long lengthXa, lengthXb, lengthXc, pX, pY;
    lengthXa = xOne1 - xOne0;
    lengthXb = xTwo1 - xTwo0;
    lengthXc = xThree1 - xThree0;
    pX = 2 * (lengthXa + lengthXb + lengthXc - reunionXab - reunionXac - reunionXbc + reunionX);

    long long lengthYa, lengthYb, lengthYc;
    lengthYa = yOne1 - yOne0;
    lengthYb = yTwo1 - yTwo0;
    lengthYc = yThree1 - yThree0;
    pY = 2 * (lengthYa + lengthYb + lengthYc - reunionYab - reunionYac - reunionYbc + reunionY);

    fout << pX + pY;
}