Cod sursa(job #2853923)

Utilizator Darius_CDarius Chitu Darius_C Data 20 februarie 2022 18:49:29
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.45 kb
// Reuniune.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <fstream>
std::ifstream fin("reuniune.in");
std::ofstream fout("reuniune.out");
using namespace std;
typedef long long ll;

struct Doru {
	ll x0, y0;
	ll x1, y1;
};

bool exists(struct Doru A)
{
	if (!(A.x0 <= A.x1))
		return false;
	if (!(A.y0 <= A.y1))
		return false;
	return true;
}

ll Arie(struct Doru A)
{
	if (!exists(A))
		return 0;
	ll arie = (A.x1 - A.x0) * (A.y1 - A.y0);
	return arie;
}

ll Perimetru(struct Doru A)
{
	if (!exists(A))
		return 0;
	ll l1 = A.y1 - A.y0, l2 = A.x1 - A.x0;
	ll perimetru = 2 * (l1 + l2);
	return perimetru;
}

struct Doru intersect(struct Doru A, struct Doru B)
{
	struct Doru ret;
	ret.x0 = max(A.x0, B.x0);
	ret.x1 = min(A.x1, B.x1);
	ret.y0 = max(A.y0, B.y0);
	ret.y1 = min(A.y1, B.y1);
	return ret;
}

int main()
{
	struct Doru A, B, C;
	fin >> A.x0 >> A.y0 >> A.x1 >> A.y1;
	fin >> B.x0 >> B.y0 >> B.x1 >> B.y1;
	fin >> C.x0 >> C.y0 >> C.x1 >> C.y1;
	struct Doru D, E, F, G;
	D = intersect(A, B);
	E = intersect(B, C);
	F = intersect(C, A);
	G = intersect(D, E);

	ll arie = 0;
	arie = Arie(A) + Arie(B) + Arie(C) - Arie(D) - Arie(E) - Arie(F) + Arie(G);
	ll perimetru = 0;
	perimetru = Perimetru(A) + Perimetru(B) + Perimetru(C) - Perimetru(D) - Perimetru(E) - Perimetru(F) + Perimetru(G);
	fout << arie << " " << perimetru;
	return 0;
}