Pagini recente » Cod sursa (job #2606508) | Cod sursa (job #1552935) | Cod sursa (job #1775920) | Cod sursa (job #2107855) | Cod sursa (job #1184690)
#include <fstream>
#include <algorithm>
struct DREPT{long long x0,y0,x1,y1;}; //x0<=x1 and y0<=y1
void intersect(DREPT &to, const DREPT &a, const DREPT &b){
bool bothnull=false;
if(a.x0<=b.x0){
if(a.x1<b.x0) bothnull=true;
else if(a.x1==b.x0){ to.x0=a.x1; to.x1=a.x1; }
else { to.x0=b.x0; to.x1=std::min(a.x1,b.x1); }
}
else{
if(b.x1<a.x0) bothnull=true;
else if(b.x1==a.x0){ to.x0=b.x1; to.x1=b.x1; }
else { to.x0=a.x0; to.x1=std::min(a.x1,b.x1); }
}
if(a.y0<=b.y0){
if(a.y1<b.y0) bothnull=true;
else if(a.y1==b.y0){ to.y0=a.y1; to.y1=a.y1; }
else { to.y0=b.y0; to.y1=std::min(a.y1,b.y1); }
}
else{
if(b.y1<a.y0) bothnull=true;
else if(b.y1==a.y0){ to.y0=b.y1; to.y1=b.y1; }
else { to.y0=a.y0; to.y1=std::min(a.y1,b.y1); }
}
if(bothnull){ to.x0=0; to.x1=0; to.y0=0; to.y1=0; }
}
inline long long arie(const DREPT &d){
return (d.x1-d.x0)*(d.y1-d.y0);
}
inline long long perim(const DREPT &d){
return 2*(d.x1-d.x0+d.y1-d.y0);
}
int main(){
std::ifstream fin("reuniune.in");
std::ofstream fout("reuniune.out");
DREPT a,b,c,axb,bxc,axc,axbxc;
fin>>a.x0>>a.y0>>a.x1>>a.y1;
fin>>b.x0>>b.y0>>b.x1>>b.y1;
fin>>c.x0>>c.y0>>c.x1>>c.y1;
intersect(axb,a,b);
intersect(bxc,b,c);
intersect(axc,a,c);
intersect(axbxc,axc,axb);
fout<<arie(a)+arie(b)+arie(c)-arie(axb)-arie(axc)-arie(bxc)+arie(axbxc)<<' ';
fout<<perim(a)+perim(b)+perim(c)-perim(axb)-perim(axc)-perim(bxc)+perim(axbxc)<<'\n';
}