Cod sursa(job #2811614)

Utilizator JaguarKatStere Teodor Ioanin JaguarKat Data 2 decembrie 2021 18:35:04
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <bits/stdc++.h>

using namespace std;

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

struct dreptunghi
{
	long long x1, y1, x2, y2;
}doru[3];

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

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

dreptunghi intersectate(dreptunghi a, dreptunghi b)
{
	dreptunghi c;
	c.x1 = max(a.x1, b.x1);
	c.y1 = max(a.y1, b.y1);
	c.x2 = min(a.x2, b.x2);
	c.y2 = min(a.y2, b.y2);
	if(c.x1 <= c.x2 and c.y1 <= c.y2)return c;
	else
	{
		c.x1 = c.x2 = c.y1 = c.y2 = 0;
		return c;
	}
}

int main()
{
	for(int i = 0; i <= 2; ++i)
	{
		fin >> doru[i].x1 >> doru[i].y1 >> doru[i].x2 >> doru[i].y2;
	}
	fout << arie(doru[0]) + arie(doru[1]) + arie(doru[2]) - arie(intersectate(doru[0], doru[1])) - arie(intersectate(doru[1], doru[2])) - arie(intersectate(doru[2], doru[0])) + arie(intersectate(doru[0], intersectate(doru[1], doru[2])));
	fout << ' ';
	fout << perimetru(doru[0]) + perimetru(doru[1]) + perimetru(doru[2]) - perimetru(intersectate(doru[0], doru[1])) - perimetru(intersectate(doru[1], doru[2])) - perimetru(intersectate(doru[2], doru[0])) + perimetru(intersectate(doru[0], intersectate(doru[1], doru[2])));
	return 0;
}