Cod sursa(job #3200661)

Utilizator ililogIlinca ililog Data 5 februarie 2024 16:36:50
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
using namespace std;
#include<iostream>
#include<fstream>

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

struct dreptunghi {
    long long x1, y1;
    long long x2, y2;
} d1, d2, d3;

long long aria(dreptunghi a) {
    return (a.x2 - a.x1) * (a.y2 - a.y1);
}

long long perimetru(dreptunghi a) {
    return 2*((a.x2-a.x1) + (a.y2-a.y1));
}

dreptunghi intersectie(dreptunghi a, dreptunghi b) {
    
    dreptunghi i;
    
    if (a.x2 < b.x1 || b.x2 < a.x1 || a.y2 < b.y1 || b.y2 < a.y1) {
        i = {0,0,0,0};
        return i;
    }
    
    i.x1 = max(a.x1, b.x1);
    i.x2 = min(a.x2, b.x2);
    i.y1 = max(a.y1, b.y1);
    i.y2 = min(a.y2, b.y2);
    
    return i;
}

int main() {
    
    fin >> d1.x1 >> d1.y1 >> d1.x2 >> d1.y2;
    fin >> d2.x1 >> d2.y1 >> d2.x2 >> d2.y2;
    fin >> d3.x1 >> d3.y1 >> d3.x2 >> d3.y2;
    
    dreptunghi d1nd2 = intersectie(d1, d2);
    dreptunghi d1nd3 = intersectie(d1, d3);
    dreptunghi d2nd3 = intersectie(d2, d3);
    dreptunghi d1nd2nd3 = intersectie(d1nd2, d3);
    
    long long s = aria(d1) + aria(d2) + aria(d3);
    s = s - aria(d1nd2) - aria(d1nd3) - aria(d2nd3);
    s = s + aria(d1nd2nd3);
    
    long long p = perimetru(d1) + perimetru(d2) + perimetru(d3);
    p = p - perimetru(d1nd2) - perimetru(d1nd3) - perimetru(d2nd3);
    p = p + perimetru(d1nd2nd3);
    
    fout << s << " " << p;
    
    return 0;
}