Pagini recente » Cod sursa (job #1110605) | Cod sursa (job #220556) | Cod sursa (job #2888649) | Cod sursa (job #742093) | Cod sursa (job #3200660)
using namespace std;
#include<iostream>
#include<fstream>
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
struct dreptunghi {
int x1, y1;
int x2, y2;
} d1, d2, d3;
int aria(dreptunghi a) {
return (a.x2 - a.x1) * (a.y2 - a.y1);
}
int 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);
int s = aria(d1) + aria(d2) + aria(d3);
s = s - aria(d1nd2) - aria(d1nd3) - aria(d2nd3);
s = s + aria(d1nd2nd3);
int p = perimetru(d1) + perimetru(d2) + perimetru(d3);
p = p - perimetru(d1nd2) - perimetru(d1nd3) - perimetru(d2nd3);
p = p + perimetru(d1nd2nd3);
fout << s << " " << p;
return 0;
}