Cod sursa(job #1223719)

Utilizator HotSteelBeteag Ion Andrei HotSteel Data 28 august 2014 17:37:28
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.64 kb
#include <cstdio>
#include <algorithm>

long long abs(long long x)
{
	if(x>0)
		return x;

	return x*(-1);
}

class dreptunghi
{
	private:
		int x1,y1,x2,y2;
	public:
		dreptunghi() : x1(0), y1(0), x2(0), y2(0)
		{}
		dreptunghi(int _x1,int _y1,int _x2,int _y2) : x1(_x1), y1(_y1), x2(_x2), y2(_y2)
		{}

		int getx1()
		{
			return x1;
		}
		int getx2()
		{
			return x2;
		}
		int gety1()
		{
			return y1;
		}
		int gety2()
		{
			return y2;
		}

		dreptunghi comun(dreptunghi drp)
		{
			int x1,y1,x2,y2;
			x1 = std::max(this->x1,drp.getx1());
			x2 = std::min(this->x2,drp.getx2());
			y1 = std::max(this->y1,drp.gety1());
			y2 = std::min(this->y2,drp.gety2());

			if(x1 > x2 || y1 > y2)
				return dreptunghi();

			return dreptunghi(x1,y1,x2,y2);
		}

		long long arie()
		{
			return abs(x1-x2)*abs(y1-y2);
		}

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

int main()
{
    freopen("reuniune.in","r",stdin);
    freopen("reuniune.out","w",stdout);

	dreptunghi a,b,c;
	int x1,y1,x2,y2;

	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	a=dreptunghi(x1,y1,x2,y2);
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	b=dreptunghi(x1,y1,x2,y2);
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	c=dreptunghi(x1,y1,x2,y2);

	long long arie = a.arie() + b.arie() + c.arie() - a.comun(b).arie() - a.comun(c).arie() - b.comun(c).arie() + a.comun(b).comun(c).arie();
	long long perimetru = a.perimetru() + b.perimetru() + c.perimetru() - a.comun(b).perimetru() - a.comun(c).perimetru() - b.comun(c).perimetru() + a.comun(b).comun(c).perimetru();

	printf("%lld %lld",arie,perimetru);

    return 0;
}