Cod sursa(job #2068435)

Utilizator rebecca0312Andrei Rebecca rebecca0312 Data 17 noiembrie 2017 20:57:46
Problema Reuniune Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.09 kb
#include<cstdio>
#include<algorithm>
using namespace std;

int x1[5],y1[5],x2[5],y2[5];
pair<int, pair<int, pair<int, int>>> nr12,nr13,nr23,nr123;

pair<int, pair<int, pair<int, int>>> intersectie(int ind1, int ind2){
    pair<int, pair<int, pair<int, int>>> nr;
    int a1,b1,a2,b2;
    a1=max(x1[ind1], x1[ind2]);
    a2=min(x2[ind1], x2[ind2]);
    b1=max(y1[ind1], y1[ind2]);
    b2=min(y2[ind1], y2[ind2]);
    nr.first=a1;
    nr.second.first=b1;
    nr.second.second.first=a2;
    nr.second.second.second=b2;
    return nr;
}

bool contradictie(){
    if(nr123.first>nr123.second.second.first)
        return true;
    if(nr123.second.first>nr123.second.second.second)
        return true;
    return false;
}

void initializare(){
    nr123.first=nr123.second.first=nr123.second.second.first=nr123.second.second.second=0;
}

long long produs(pair<int, pair<int, pair<int, int>>> nr){
    long long s;
    s=1LL*(nr.second.second.first-nr.first)*(nr.second.second.second-nr.second.first);
    return s;
}

long long suma(pair<int, pair<int, pair<int, int>>> nr){
    long long s=0;
    s=1LL*2*(nr.second.second.first-nr.first+nr.second.second.second-nr.second.first);
    return s;
}

int main(){
    freopen("reuniune.in","r",stdin);
    freopen("reuniune.out","w",stdout);
    long long arie=0,perimetru=0;
    for(int k=1;k<=3;k++)
        scanf("%d%d%d%d", &x1[k], &y1[k], &x2[k], &y2[k]);
    nr12=intersectie(1, 2);
    nr13=intersectie(1, 3);
    nr23=intersectie(2, 3);
    nr123.first=max(x1[1], max(x1[2], x1[3]));
    nr123.second.first=max(y1[1], max(y1[2], y1[3]));
    nr123.second.second.first=min(x2[1], min(x2[2], x2[3]));
    nr123.second.second.second=min(y2[1], min(y2[2], y2[3]));
    if(contradictie())
        initializare();
    for(int k=1;k<=3;k++){
        arie+=1LL*(x2[k]-x1[k])*(y2[k]-y1[k]);
        perimetru+=1LL*2*(x2[k]-x1[k]+y2[k]-y1[k]);
    }
    arie-=produs(nr12)+produs(nr13)+produs(nr23)-produs(nr123);
    perimetru-=suma(nr12)+suma(nr13)+suma(nr23)-suma(nr123);
    printf("%lld %lld", arie, perimetru);
    return 0;
}