Cod sursa(job #1586370)

Utilizator Debuger33Numarul1 Debuger33 Data 1 februarie 2016 06:47:39
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <iostream>
#include <fstream>

using namespace std;

#define max(x,y) (x)<(y)?y:x;
#define min(x,y) (x)<(y)?x:y;


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


struct dreptunghi
{
	  long long int x1,x2,y1,y2;
};

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

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

dreptunghi inter ( dreptunghi a , dreptunghi b)
{
	  dreptunghi nou;

	  nou.x1 = max(a.x1,b.x1);
	  nou.y1 = max(a.y1,b.y1);
	  nou.x2 = min(a.x2,b.x2);
	  nou.y2 = min(a.y2,b.y2);

	  if( nou.x2 < nou.x1 || nou.y2 < nou.y1)
	  {
		    nou.x1 = 0;
		    nou.y1 = 0;
		    nou.x2 = 0;
		    nou.y2 = 0;
	  }

	  return nou;
}

int main()
{
	  dreptunghi a , b ,c ;

	  fin >> a.x1 >> a.y1 >> a.x2 >>a.y2 >> b.x1 >> b.y1 >> b.x2 >> b.y2 >> c.x1 >> c.y1 >> c.x2 >>c.y2 ;

	  fin.close();

	  long long int  ar , pr;

	  dreptunghi d1 = inter(a,b);
	  dreptunghi d2 = inter(b,c);
	  dreptunghi d3 = inter(c,a);
	  dreptunghi d4 = inter(d1,c);

	  ar = arie(a) + arie(b) + arie(c) - arie(d1) - arie(d2) - arie(d3) +arie(d4);
	  pr = perimetru(a) + perimetru(b) + perimetru(c) - perimetru(d1) - perimetru(d2) - perimetru(d3) +perimetru(d4);

	  fout << ar << " " << pr;

	  fout.close();

	  return 0;
}