Cod sursa(job #2162385)

Utilizator MoldooooooooMoldoveanu Stefan Moldoooooooo Data 12 martie 2018 10:35:00
Problema Reuniune Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 5.69 kb
#include <fstream>
#include <utility>
using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
long int Pozx[6];
long int Pozy[6];
int k, pp, u=0; long int a=0, b=0, c=0, d=0;
pair <long long int, long long int> X(long int x0, long int x1, long int y0, long int y1, long int x00, long int x01, long int y00, long int y01){
    pair<long long int, long long int> AS; AS.first=AS.second=k=0;
    if(x0<x00 && x00<x1 && x1<x01 && y0<y00 && y00<y1 && y1<y01) {AS.first=(x1-x00)*(y1-y00); AS.second=2*(x1-x00+y1-y00); k++; u++;
                           if(u==1){a=x00; b=y00; c=x1; d=y1; u++;} return AS;}
    if(x00<x0 && x0<x01 && x01<x1 && y0<y00 && y00<y1 && y1<y01) {AS.first=(x01-x0)*(y1-y00); AS.second=2*(x01-x0+y1-y00); k++; u++;
                           if(u==1){a=x0; b=y00; c=x01; d=y1; u++;} return AS;}
    if(x00<x0 && x0<x01 && x01<x1 && y00<y0 && y0<y01 && y01<y1) {AS.first=(x01-x0)*(y01-y0); AS.second=2*(x01-x0+y01-y0); k++; u++;
                           if(u==1){a=x0; b=y0; c=x01; d=y01; u++;} return AS;}
    if(x0<x00 && x00<x1 && x1<x01 && y00<y0 && y00<y1 && y01<y1) {AS.first=(x1-x00)*(y01-y0); AS.second=2*(x1-x00+y01-y0); k++; u++;
                           if(u==1){a=x00; b=y0; c=x1; d=y01; u++;} return AS;}
    return AS;
}

pair <long long int, long long int> U(long int x0, long int x1, long int y0, long int y1, long int x00, long int x01, long int y00, long int y01){
    pair<long long int, long long int> AS; AS.first=AS.second=pp=k=0;
    if(x0<=x00 && x00<x01 && x01<=x1 && y00<y0 && y0<y01 && y01<y1) {AS.first=(x01-x00)*(y01-y0); AS.second=2*(x01-x00+y01-y0); k++; u++;
                           if(u==1){a=x00; b=y0; c=x01; d=y01; u++;} return AS;}
    if(x0<x00 && x00<x1 && x1<x01 && y0<=y00 && y00<y01 && y01<=y1) {AS.first=(x1-x00)*(y01-y00); AS.second=2*(x1-x00+y01-y00); k++; u++;
                           if(u==1){a=x00; b=y00; c=x1; d=y01; u++;} return AS;}
    if(x0<=x00 && x00<x01 && x01<=x1 && y0<y00 && y00<y1 && y1<y01) {AS.first=(x01-x00)*(y1-y00); AS.second=2*(x01-x00+y1-y00); k++; u++;
                           if(u==1){a=x00; b=y00; c=x01; d=y1; u++;} return AS;}
    if(x00<x0 && x0<x01 && x01<x1 && y0<=y00 && y00<y01 && y01<=y1) {AS.first=(x01-x0)*(y01-y00); AS.second=2*(x01-x0+y01-y00); k++; u++;
                           if(u==1){a=x0; b=y00; c=x01; d=y01; u++;} return AS;}
    if(pp==0) {pp++; AS.first=U(x00, x01, y00, y01, x0, x1, y0, y1).first;
               AS.second=U(x00, x01, y00, y01, x0, x1, y0, y1).second;}
    return AS;
}

pair <long long int, long long int> I(long int x0, long int x1, long int y0, long int y1, long int x00, long int x01, long int y00, long int y01){
    pair<long long int, long long int> AS; AS.first=AS.second=pp=k=0;
    if(x0<=x00 && x00<x01 && x01<=x1 && y0<=y00 && y00<y01 && y01<=y1) {AS.first=(x01-x00)*(y01-y00); AS.second=2*(x01-x00+y01-y00); k++; u++;
                           if(u==1){a=x00; b=y00; c=x01; d=y01; u++;} return AS;}
    if(k==0) {k++;
              AS.first=I(x00, x01, y00, y01, x0, x1, y0, y1).first;
              AS.second=I(x00, x01, y00, y01, x0, x1, y0, y1).second;}
    return AS;
}

int main()
{
    int i, Ar=0, Su=0;
    for(i=0; i<6; i++) fin>>Pozx[i]>>Pozy[i];
    Ar=((Pozx[1]-Pozx[0])*(Pozy[1]-Pozy[0])+(Pozx[3]-Pozx[2])*(Pozy[3]-Pozy[2])+(Pozx[5]-Pozx[4])*(Pozy[5]-Pozy[4]));
    Su=2*(Pozx[1]-Pozx[0]+Pozy[1]-Pozy[0]+Pozx[3]-Pozx[2]+Pozy[3]-Pozy[2]+Pozx[5]-Pozx[4]+Pozy[5]-Pozy[4]);
    Ar-=X(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).first;
    Su-=X(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).second;
    if(k==0){
        Ar-=U(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).first;
        Su-=U(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).second;
    }
    if(k==0){
        Ar-=I(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).first;
        Su-=I(Pozx[0], Pozx[1], Pozy[0], Pozy[1], Pozx[2], Pozx[3], Pozy[2], Pozy[3]).second;
    }
    Ar-=X(Pozx[2], Pozx[3], Pozy[2], Pozy[3], Pozx[4], Pozx[5], Pozy[4], Pozy[5]).first;
    Su-=X(Pozx[2], Pozx[3], Pozy[2], Pozy[3], Pozx[4], Pozx[5], Pozy[4], Pozy[5]).second;
    if(k==0){
        Ar-=U(Pozx[2], Pozx[3], Pozy[2], Pozy[3], Pozx[4], Pozx[5], Pozy[4], Pozy[5]).first;
        Su-=U(Pozx[2], Pozx[3], Pozy[2], Pozy[3], Pozx[4], Pozx[5], Pozy[4], Pozy[5]).second;
    }
    if(k==0){
        Ar-=U(Pozx[2], Pozx[3], Pozy[2], Pozy[3], Pozx[4], Pozx[5], Pozy[4], Pozy[5]).first;
        Su-=U(Pozx[2], Pozx[3], Pozy[2], Pozy[3], Pozx[4], Pozx[5], Pozy[4], Pozy[5]).second;
    }
    Ar-=X(Pozx[4], Pozx[5], Pozy[4], Pozy[5], Pozx[0], Pozx[1], Pozy[0], Pozy[1]).first;
    Su-=X(Pozx[4], Pozx[5], Pozy[4], Pozy[5], Pozx[0], Pozx[1], Pozy[0], Pozy[1]).second;
    if(k==0){
        Ar-=U(Pozx[4], Pozx[5], Pozy[4], Pozy[5], Pozx[0], Pozx[1], Pozy[0], Pozy[1]).first;
        Su-=U(Pozx[4], Pozx[5], Pozy[4], Pozy[5], Pozx[0], Pozx[1], Pozy[0], Pozy[1]).second;
    }
    if(k==0){
        Ar-=I(Pozx[4], Pozx[5], Pozy[4], Pozy[5], Pozx[0], Pozx[1], Pozy[0], Pozy[1]).first;
        Su-=I(Pozx[4], Pozx[5], Pozy[4], Pozy[5], Pozx[0], Pozx[1], Pozy[0], Pozy[1]).second;
    }
    Ar+=X(Pozx[4], Pozx[5], Pozy[4], Pozy[5], a, c, b, d).first;
    Su+=X(Pozx[4], Pozx[5], Pozy[4], Pozy[5], a, c, b, d).second;
    if(k==0){
        Ar+=U(Pozx[4], Pozx[5], Pozy[4], Pozy[5], a, c, b, d).first;
        Su+=U(Pozx[4], Pozx[5], Pozy[4], Pozy[5], a, c, b, d).second;
    }
    if(k==0){
        Ar+=I(Pozx[4], Pozx[5], Pozy[4], Pozy[5], a, c, b, d).first;
        Su+=I(Pozx[4], Pozx[5], Pozy[4], Pozy[5], a, c, b, d).second;
    }
    fout<<Ar<<" "<<Su;
    return 0;
}