Cod sursa(job #114250)

Utilizator Adriana_SAdriana Sperlea Adriana_S Data 13 decembrie 2007 16:35:05
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <stdio.h>
#include <algorithm>

using namespace std;

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

dreptunghi a, b, c;

dreptunghi inter(dreptunghi a, dreptunghi b)
{
	if ((b.x1 > a.x2) || (b.x2 < a.x1) || (b.y1 > a.y2) || (b.y2 < a.y1)) {
		dreptunghi c;
		c.x1 = 0, c.y1 = 0, c.x2 = 0, c.y2 = 0;
		return c;
	}
 	
	long long vx[5], vy[5];
 	vx[1] = a.x1, vx[2] = a.x2, vx[3] = b.x1, vx[4] = b.x2;
 	sort(vx + 1, vx + 5);

 	vy[1] = a.y1, vy[2] = a.y2, vy[3] = b.y1, vy[4] = b.y2;
 	sort(vy + 1, vy + 5);

 	dreptunghi d;
 	d.x1 = vx[2], d.y1 = vy[2], d.x2 = vx[3], d.y2 = vy[3];
 	return d;
}

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

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

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

	//citire
 	scanf("%lld %lld %lld %lld", &a.x1, &a.y1, &a.x2, &a.y2);
	scanf("%lld %lld %lld %lld", &b.x1, &b.y1, &b.x2, &b.y2);
	scanf("%lld %lld %lld %lld", &c.x1, &c.y1, &c.x2, &c.y2);
	
	//determinare arie si intersectie
 	long long ar = 0, p = 0;
 	ar += (arie(a) + arie(b) + arie(c));
	p += (per(a) + per(b) + per(c));
	
	dreptunghi aux;
	aux = inter(a, b);
	ar -= arie(aux);
	p -= per(aux);
	aux = inter(b, c);
	ar -= arie(aux);
	p -= per(aux);
	aux = inter(c, a);
	ar -= arie(aux);
	p -= per(aux);

	aux = inter(a, b);
	aux = inter(aux, c);
	ar += arie(aux);
	p += per(aux);
	
	printf("%lld %lld", ar, p);

	fclose(stdin);
	fclose(stdout);

	return 0;
}