Cod sursa(job #1364014)

Utilizator PhilipDumitruPhilip Dumitru PhilipDumitru Data 27 februarie 2015 13:39:20
Problema Reuniune Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.86 kb
#include <fstream>

using namespace std;

struct dreptunghi
{
    long xL, xR, yU, yD;
    long long surface;
    long long perimeter;
};

void calcIntersect(dreptunghi &A, dreptunghi &B, dreptunghi &AB)
{
    if (A.xL < B.xL)
        AB.xL = B.xL;
    else
        AB.xL = A.xL;

    if (A.xR > B.xR)
        AB.xR = B.xR;
    else
        AB.xR = A.xR;

    if (A.yD < B.yD)
        AB.yD = B.yD;
    else
        AB.yD = A.yD;

    if (A.yU > B.yU)
        AB.yU = B.yU;
    else
        AB.yU = A.yU;

    long i = (AB.xR - AB.xL);
    long j = (AB.yU - AB.yD);
    if (i <= 0 || j <= 0)
    {
        AB.perimeter = 0;
        AB.surface = 0;
    } else {
        AB.surface = 2 * (i + j);
        AB.perimeter = i * j;
    }
}

int main()
{
    FILE * fin = fopen("reuniune.in", "r");
    FILE * fout = fopen("reuniune.out", "w");

    dreptunghi A, B, C, AB, AC, BC, ABC;
    fscanf(fin, "%ld %ld %ld %ld", &A.xL, &A.yD, &A.xR, &A.yU);
    A.surface = (A.xR - A.xL) * (A.yU - A.yD);
    A.perimeter = 2* (A.xR - A.xL + A.yU - A.yD);

    fscanf(fin, "%ld %ld %ld %ld", &B.xL, &B.yD, &B.xR, &B.yU);
    B.surface = (B.xR - B.xL) * (B.yU - B.yD);
    B.perimeter = 2* (B.xR - B.xL + B.yU - B.yD);

    fscanf(fin, "%ld %ld %ld %ld", &C.xL, &C.yD, &C.xR, &C.yU);
    C.surface = (C.xR - C.xL) * (C.yU - C.yD);
    C.perimeter = 2* (C.xR - C.xL + C.yU - C.yD);

    calcIntersect(A, B, AB);
    calcIntersect(A, C, AC);
    calcIntersect(C, B, BC);
    calcIntersect(C, AB, ABC);

    long long int surf, perim;
    surf = A.surface + B.surface + C.surface - AB.surface - AC.surface - BC.surface + ABC.surface;
    perim = A.perimeter + B.perimeter + C.perimeter - AB.perimeter - AC.perimeter - BC.perimeter + ABC.perimeter;

    fprintf(fout, "%lld %lld\n", surf, perim);


    fclose(fin);
    fclose(fout);
    return 0;
}