Cod sursa(job #114246)

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

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

dreptunghi a, b, c;

int par(int p, int r, long long v[5])
{long long x = v[r], aux;
 int i = p - 1, j;
 for (j = p; j < r; j ++)
	if (v[j] < x)
	 {
		i ++;
		aux = v[i];
		v[i] = v[j];
		v[j] = aux;
	 }
 aux = v[i + 1];
 v[i + 1] = v[r];
 v[r] = aux;
 return (i + 1);}

void quick(int p, int r, long long v[5])
{if (p < r)
  {
	int q = par(p, r, v);
	quick(q + 1, r, v);
	quick(p, q - 1, v);
  }}

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;
 quick(1, 4, vx);
 vy[1] = a.y1, vy[2] = a.y2, vy[3] = b.y1, vy[4] = b.y2;
 quick(1, 4, vy);
 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);
 //am determinat aria si perimetru. ce tare sunt:D

 printf("%lld %lld", ar, p);

 //am si afisat ceam determinat, sunt si mai tare:D

 fclose(stdin);
 fclose(stdout);
 return 0;}