Cod sursa(job #2750859)

Utilizator NashikAndrei Feodorov Nashik Data 13 mai 2021 14:16:05
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.69 kb
//#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream cin("reuniune.in");
ofstream cout("reuniune.out");
struct dreptunghi{
    long long x0,y0,x1,y1,arie,perimetru;
}v[10];
long long pe(dreptunghi a){
    return (a.x1-a.x0+a.y1-a.y0)*2;
}
dreptunghi intersectie(dreptunghi a,dreptunghi b){
    dreptunghi x;
    if(a.arie==0 or b.arie==0){
        x.arie=0;
        x.x0=0;
        x.y0=0;
        x.x1=0;
        x.y1=0;
        return x;
    }
    x.x0=max(a.x0,b.x0);
    x.y0=max(a.y0,b.y0);
    x.x1=min(a.x1,b.x1);
    x.y1=min(a.y1,b.y1);
    if(x.x0>x.x1 or x.y0>x.y1){
        x.arie=0;
        x.x0=0;
        x.y0=0;
        x.x1=0;
        x.y1=0;
    }
    else
        x.arie=(x.x1-x.x0)*(x.y1-x.y0);
    return x;
}
int main()
{
    long long mi1=1000000005,mi2=1000000005,ma1=-1000000005,ma2=-1000000005;
    for(long long i=1;i<=3;i++){
        cin>>v[i].x0>>v[i].y0>>v[i].x1>>v[i].y1;
        if(v[i].x0>=v[i].x1 or v[i].y0>=v[i].y1){
            v[i].arie=0;
        }
        else
            v[i].arie=(v[i].x1-v[i].x0)*(v[i].y1-v[i].y0);
        mi1=min(mi1,v[i].x0);
        mi2=min(mi2,v[i].y0);
        ma1=max(ma1,v[i].x1);
        ma2=max(ma2,v[i].y1);
    }
    v[4]=intersectie(v[1],v[2]);
    v[5]=intersectie(v[1],v[3]);
    v[6]=intersectie(v[3],v[2]);
    v[7]=intersectie(v[4],intersectie(v[5],v[6]));
    long long aria=v[1].arie+v[2].arie+v[3].arie-v[4].arie-v[5].arie-v[6].arie+v[7].arie;
    cout<<aria<<" ";
    cout/*<<" "<<abs(2*((mi1-ma1)+(mi2-ma2)))<<" "*/<<pe(v[1])+pe(v[2])+pe(v[3])-pe(v[4])-pe(v[5])-pe(v[6])+pe(v[7]);
    return 0;
}
/*
1 2 3 4
5 6 7 8
9 10 11 12
12
 40 24
*/