Cod sursa(job #1364419)

Utilizator j.loves_rockJessica Joanne Patrascu j.loves_rock Data 27 februarie 2015 17:34:19
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.89 kb
#include <fstream>

using namespace std;

struct dreptunghi
{
    long 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 long i = (AB.xR - AB.xL);
    long long j = (AB.yU - AB.yD);
    if (i < 0 || j < 0)
    {
        AB.perimeter = 0;
        AB.surface = 0;
    } else {
        AB.perimeter = 2 * (i + j);
        AB.surface = 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, "%lld %lld %lld %lld", &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, "%lld %lld %lld %lld", &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, "%lld %lld %lld %lld", &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;
}