Cod sursa(job #2437235)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 8 iulie 2019 21:50:00
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <bits/stdc++.h>

using namespace std;

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

struct dreptunghi
{
    long long x,y,x2,y2;
    long long arie()
    {
        return 1LL * (x2 - x) * (y2 - y);
    }
    long long per()
    {
        return ((x2 - x) + (y2 - y)) * 2LL;
    }
}d1, d2, d3, d12, d13, d23, d123;

bool Inside(long long x, long long y, dreptunghi a)
{
    return x >= a.x && x <= a.x2 && y >= a.y && y <= a.y2;
}

dreptunghi Intersection(dreptunghi a, dreptunghi b)
{
    dreptunghi p = {0, 0, 0, 0};
    int max1 = -10000000001;
    int max2 = -10000000001;
    int min1 = 10000000001;
    int min2 = 10000000001;
    max1 = max(a.x, b.x);
    max2 = max(a.y, b.y);
    min1 = min(a.x2, b.x2);
    min2 = min(a.y2, b.y2);
    if (max1 <= min1 && max2 <= min2)
    {
        p = {max1, max2, min1, min2};
    }
    return p;
}

int main()
{
    fin >> d1.x >> d1.y >> d1.x2 >> d1.y2;
    fin >> d2.x >> d2.y >> d2.x2 >> d2.y2;
    fin >> d3.x >> d3.y >> d3.x2 >> d3.y2;
    d12 = Intersection(d1, d2);
    d13 = Intersection(d1, d3);
    d23 = Intersection(d2, d3);
    d123 = Intersection(d12, d3);
    fout << d1.arie()+d2.arie()+d3.arie()-d12.arie()-d13.arie()-d23.arie()+d123.arie() << " ";
    fout << d1.per()+d2.per()+d3.per()-d12.per()-d13.per()-d23.per()+d123.per();
    fin.close();
    fout.close();
    return 0;
}