Pagini recente » Cod sursa (job #2626184) | Cod sursa (job #689903) | Cod sursa (job #2924754) | Cod sursa (job #531987) | Cod sursa (job #3275348)
#include <fstream>
using namespace std;
struct dreptunghi
{
int x0, y0, x1, y1;
};
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
inline long long arie(const dreptunghi& d)
{
return 1LL * (d.x1 - d.x0) * (d.y1 - d.y0);
}
inline long long perimetru(const dreptunghi& d)
{
return 2LL * (d.x1 - d.x0 + d.y1 - d.y0);
}
dreptunghi intersectie(const dreptunghi& d1, const dreptunghi& d2)
{
dreptunghi d;
d.x0 = max(d1.x0, d2.x0);
d.y0 = max(d1.y0, d2.y0);
d.x1 = min(d1.x1, d2.x1);
d.y1 = min(d1.y1, d2.y1);
if(d.x0 > d.x1 || d.y0 > d.y1) d.x0 = d.y0 = d.x1 = d.y1 = 0;
return d;
}
int main()
{
dreptunghi d[3], dd;
long long a = 0, p = 0;
for(int i = 0; i < 3; ++i)
{
fin >> d[i].x0 >> d[i].y0 >> d[i].x1 >> d[i].y1;
a += arie(d[i]), p += perimetru(d[i]);
}
for(int i = 0; i < 2; ++i)
for(int j = i + 1; j < 3; ++j)
{
dd = intersectie(d[i], d[j]);
a -= arie(dd), p -= perimetru(dd);
}
dd = intersectie(intersectie(d[0], d[1]), d[2]);
a += arie(dd), p += perimetru(dd);
fout << a << ' ' << p;
return 0;
}