Cod sursa(job #531448)

Utilizator SadmannCornigeanu Calin Sadmann Data 9 februarie 2011 18:15:04
Problema Reuniune Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include<stdio.h>
FILE *in,*out;
typedef struct dreptunghi
{
	double x1,y1;
	double x2,y2;
};

double perimetru(dreptunghi x)
{
	return 2*(x.x2-x.x1)+2*(x.y2-x.y1);

}
double aria(dreptunghi x)
{
	return (x.x2-x.x1)*(x.y2-x.y1);
}

double max(double x, double y)
{
	if(x>y)
		return x;
	return y;
}

double min(long long x, long long y)
{
	if(x<y)
		return x;
	return y;
}

dreptunghi intersectie(dreptunghi x, dreptunghi y)
{
	dreptunghi i;
    i.x1=max(x.x1,y.x1);
    i.y1=max(x.y1,y.y1);
    i.x2=min(x.x2,y.x2);
    i.y2=min(x.y2,y.y2);
    if(i.x1>i.x2 || i.y1>i.y2)
        i.x1=i.x2=i.y1=i.y2=0;
    return i;

}

dreptunghi a,b,c;
int main()
{
	in=fopen("reuniune.in","rt");
	out=fopen("reuniune.out","wt");
	fscanf(in,"%lf %lf %lf %lf",&a.x1,&a.y1,&a.x2,&a.y2);
	fscanf(in,"%lf %lf %lf %lf",&b.x1,&b.y1,&b.x2,&b.y2);
	fscanf(in,"%lf %lf %lf %lf",&c.x1,&c.y1,&c.x2,&c.y2);
	
	fprintf(out,"%.0lf ", aria(a)+aria(b)+aria(c)-aria(intersectie(a,b))-aria(intersectie(a,c))-aria(intersectie(b,c))
						+aria(intersectie(intersectie(b,c),a)));
	
	fprintf(out,"%.0lf",perimetru(a)+perimetru(b)+perimetru(c)-perimetru(intersectie(a,b))-perimetru(intersectie(b,c))
						-perimetru(intersectie(a,c))+perimetru(intersectie(intersectie(b,c),a)));  
	return 0;
}