# Cod sursa(job #37150)

Utilizator Data 24 martie 2007 17:27:05 Reuniune 20 cpp done Arhiva de probleme 1.76 kb
``````#include <stdio.h>
#include <math.h>

int aria(int x1, int y1, int x2, int y2,int a1, int b1,int a2,int b2)
{
int t1,p1,t2,p2;

if (x1 <= a1)  t1=a1;
else t1=x1;
if (y1 >= b1)  p1=b1;
else p1=y1;

if (x2 <= a2)  t2=x2;
else t2=a2;
if (y2 >= b2)  p2=y2;
else p2=b2;

return (t2-t1)*(p1-p2);

}

int perimetru(int x1, int y1, int x2, int y2,int a1, int b1,int a2,int b2)
{
int t1,p1,t2,p2;

if (x1 <= a1)  t1=a1;
else t1=x1;
if (y1 >= b1)  p1=b1;
else p1=y1;

if (x2 <= a2)  t2=x2;
else t2=a2;
if (y2 >= b2)  p2=y2;
else p2=b2;

return (t2-t1)*2 +(p1-p2)*2;

}

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

long x1s,x1j,y1s,y1j,x2s,x2j,y2s,y2j,x3s,x3j,y3s,y3j;
long arie=0, perim=0;

scanf("%ld %ld %ld %ld", &x1s, &y1j, &x1j, &y1s);
scanf("%ld %ld %ld %ld", &x2s, &y2j, &x2j, &y2s);
scanf("%ld %ld %ld %ld", &x3s, &y3j, &x3j, &y3s);

arie = (x1j-x1s)*(y1s-y1j);
arie += (x2j-x2s)*(y2s-y2j);
arie += (x3j-x3s)*(y3s-y3j);

arie -= aria(x1s,y1s,x1j,y1j,x2s,y2s,x2j,y2j);
arie -= aria(x1s,y1s,x1j,y1j,x3s,y3s,x3j,y3j);
arie -= aria(x3s,y3s,x3j,y3j,x2s,y2s,x2j,y2j);

int t1,p1,t2,p2;

if (x1s <= x2s)  t1=x2s;
else t1=x1s;
if (y1s >= y2s)  p1=y2s;
else p1=y1s;

if (x1j <= x2j)  t2=x1j;
else t2=x2j;
if (y1j >= y2j)  p2=y1j;
else p2=y2j;

arie += aria(x3s,y3s,x3j,y3j,t1,p1,t2,p2);

perim =(x1j-x1s)*2 + (y1s-y1j)*2;
perim +=(x2j-x2s)*2 + (y2s-y2j)*2;
perim +=(x3j-x3s)*2 + (y3s-y3j)*2;

perim -= perimetru(x1s,y1s,x1j,y1j,x2s,y2s,x2j,y2j);
perim -= perimetru(x1s,y1s,x1j,y1j,x3s,y3s,x3j,y3j);
perim -= perimetru(x3s,y3s,x3j,y3j,x2s,y2s,x2j,y2j);

perim += perimetru(x3s,y3s,x3j,y3j,t1,p1,t2,p2);

printf("%ld %ld", arie,perim);
return 0;
}``````