Cod sursa(job #2189718)

Utilizator MoldooooooooMoldoveanu Stefan Moldoooooooo Data 28 martie 2018 21:17:36
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.77 kb
#include <fstream>
#include <utility>
#define max(x, y) (x>y ? x : y)
#define min(x, y) (x<y ? x : y)
using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
long int Pozx[6];
long int Pozy[6];
int k = 0; long int a, b, c, d, x, y, z, t;
pair <long long int, long long int> X(long int x0, long int x1, long int y0, long int y1, long int x00, long int x01, long int y00, long int y01) {
	pair<long long int, long long int> AS; AS.first = AS.second = 0;
	a = max(x0, x00); b = min(x1, x01); c = max(y0, y00); d = min(y1, y01);
	if (a<=b && c<=d) {
		AS.first = (b - a)*(d - c); AS.second = 2 * (b - a + d - c); k++;
		if (k == 6) { x = a; y = b; z = c; t = d; } return AS;
	}
	return AS;
}


int main()
{
	long int i, Ar = 0, Su = 0;
	for (i = 0; i<6; i++) fin >> Pozx[i] >> Pozy[i];
	Ar = ((Pozx[1] - Pozx[0])*(Pozy[1] - Pozy[0]) + (Pozx[3] - Pozx[2])*(Pozy[3] - Pozy[2]) + (Pozx[5] - Pozx[4])*(Pozy[5] - Pozy[4]));
	Su = 2 * (Pozx[1] - Pozx[0] + Pozy[1] - Pozy[0] + Pozx[3] - Pozx[2] + Pozy[3] - Pozy[2] + Pozx[5] - Pozx[4] + Pozy[5] - Pozy[4]);
	Ar -= X(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).first;
	Su -= X(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).second;
	Ar -= X(Pozx[4], Pozx[5], Pozy[4], Pozy[5], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).first;
	Su -= X(Pozx[4], Pozx[5], Pozy[4], Pozy[5], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).second;
	Ar -= X(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[4], Pozx[5], Pozy[4], Pozy[5]).first;
	Su -= X(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[4], Pozx[5], Pozy[4], Pozy[5]).second;
	Ar += X(x, y, z, t, Pozx[2], Pozx[3], Pozy[2], Pozy[3]).first;
	Su += X(x, y, z, t, Pozx[2], Pozx[3], Pozy[2], Pozy[3]).second;
	fout << Ar << " " << Su;
	return 0;
}