Pagini recente » Cod sursa (job #1072102) | Cod sursa (job #3124237) | Cod sursa (job #1979107) | Cod sursa (job #2591690) | Cod sursa (job #914845)
Cod sursa(job #914845)
#include <fstream>
using namespace std;
ifstream f("reuniune.in");
ofstream g("reuniune.out");
struct dreptunghi{
long long x0,y0,x1,y1;};
long long A,P;
dreptunghi a,b,c,ab,bc,ac,abc,aux;
long long MAX(long long x,long long y);
long long MIN(long long x,long long y);
long long arie(dreptunghi d);
long long pm(dreptunghi d);
dreptunghi reuniune(dreptunghi d1,dreptunghi d2);
int main()
{
f>>a.x0>>a.y0>>a.x1>>a.y1>>b.x0>>b.y0>>b.x1>>b.y1>>c.x0>>c.y0>>c.x1>>c.y1;
ab=reuniune(a,b);
ac=reuniune(a,c);
bc=reuniune(b,c);
abc=reuniune(ab,c);
g<<arie(a)+arie(b)+arie(c)-arie(ab)-arie(bc)-arie(ac)+arie(abc)<<' ';
g<<pm(a)+pm(b)+pm(c)-pm(ab)-pm(bc)-pm(ac)+pm(abc)<<'\n';
f.close();
g.close();
return 0;
}
dreptunghi reuniune(dreptunghi d1,dreptunghi d2){
if(d1.y1>d2.y0&&d1.y0<d2.y1&&d1.x1>d2.x0&&d1.x0<d2.x1){
aux.x0=MAX(d1.x0,d2.x0);
aux.x1=MIN(d1.x1,d2.x1);
aux.y0=MAX(d1.y0,d2.y0);
aux.y1=MIN(d1.y1,d2.y1);}
else
aux.x0=aux.x1=aux.y0=aux.y1=0;
return aux;}
long long MAX(long long x,long long y){
return (x>y)?x:y;}
long long MIN(long long x,long long y){
return (x<y)?x:y;}
long long arie(dreptunghi d){
return (d.x1-d.x0)*(d.y1-d.y0);}
long long pm(dreptunghi d){
return 2*(d.x1-d.x0+d.y1-d.y0);}