Cod sursa(job #1158991)

Utilizator tudorv96Tudor Varan tudorv96 Data 29 martie 2014 11:17:09
Problema Reuniune Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.94 kb
#include <fstream>
#include <vector>
#include <iostream>
using namespace std;

ifstream fin ("reuniune.in");
ofstream fout ("reuniune.out");

typedef long long ull;

struct dreptunghi {
    ull x1, x2, y1, y2;
} v[3];

ull aria, perim;

dreptunghi intersect (dreptunghi a, dreptunghi b) {
    dreptunghi sol;
    sol.x1 = sol.x2 = sol.y1 = sol.y2 = 0;
    if (a.x1 < b.x1) {  // a incepe inaintea lui b
        if (b.x1 < a.x2) { // a se intersecteaza cu b in x-uri
            sol.x1 = b.x1;
            sol.x2 = min(b.x2, a.x2);
        }
    }
    else {
        if (a.x1 < b.x2) {
            sol.x1 = a.x1;
            sol.x2 = min(a.x2, b.x2);
        }
    }
    if (a.y1 < b.y1) {
        if (b.y1 < a.y2) {
            sol.y1 = b.y1;
            sol.y2 = min(b.y2, a.y2);
        }
    }
    else {
        if (a.y1 < b.y2) {
            sol.y1 = a.y1;
            sol.y2 = min(a.y2, b.y2);
        }
    }
    if (sol.x1 == sol.x2)
        sol.y1 = sol.y2;
    if (sol.y1 == sol.y2)
        sol.x1 = sol.x2;
    return sol;
}

int main() {
    for (int i = 0; i < 3; ++i)
        fin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
    for (int i = 1; i < 8; ++i) {
        vector <int> x;
        int nr = 0;
        for (int j = 0; (1 << j) <= i; ++j)
            if (i & (1 << j)) {
                nr++;
                x.push_back (j);
            }
        dreptunghi now = v[x[0]];
        for (int i = 1; i < x.size(); ++i)
            now = intersect (now, v[x[i]]);
        ull aria_now = (now.x2 - now.x1) * (now.y2 - now.y1), perim_now = (now.x2 - now.x1 + now.y2 - now.y1) * 2;
        cout << now.x1 << " " << now.y1 << " " << now.x2 << " " << now.y2 << "\n";
        if (nr % 2 == 0) {
            aria -= aria_now;
            perim -= perim_now;
        }
        else {
            aria += aria_now;
            perim += perim_now;
        }
    }
    fout << aria << " " << perim;
}