Cod sursa(job #1744947)

Utilizator andreistanStan Andrei andreistan Data 20 august 2016 19:12:34
Problema Reuniune Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.63 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("reuniune.in");
ofstream g("reuniune.out");
struct dreptunghiuri
{
    long long X0,Y0,X1,Y1;
};
dreptunghiuri d[4];
long long a,p;
void ariecom2(dreptunghiuri d1, dreptunghiuri d2)
{
    long long x0,y0,x1,y1;//coordonatele dreptunghiului comun
    long long x,y;//lungimile laturilor posibilului dreptunghi comun
    a=0;
    p=0;
    x0=max(d1.X0,d2.X0);
    x1=min(d1.X1,d2.X1);
    y0=max(d1.Y0,d2.Y0);
    y1=min(d1.Y1,d2.Y1);

    if((x=x1-x0)>0 && (y=y1-y0)>0)
    {
        a=x*y;
        p=2*(x+y);
    }
}

void ariecom3(dreptunghiuri d1, dreptunghiuri d2, dreptunghiuri d3)
{

    long long x0,y0,x1,y1;//coordonatele dreptunghiului comun
    long long x,y;//lungimile laturilor posibilului dreptunghi comun
    a=0;
    p=0;
    x0=max(d1.X0,d2.X0);
    x1=min(d1.X1,d2.X1);
    y0=max(d1.Y0,d2.Y0);
    y1=min(d1.Y1,d2.Y1);//intersectia primelor 2

    x0=max(x0,d3.X0);
    x1=min(x1,d3.X1);
    y0=max(y0,d3.Y0);
    y1=min(y1,d3.Y1);

    if((x=x1-x0)>0 && (y=y1-y0)>0)
    {
        a=x*y;
        p=2*(x+y);
    }
}

int main()
{
    long long A=0,P=0;//arie si perimetru total
    for(int i=1; i<=3; i++)
    {
        f>>d[i].X0>>d[i].Y0>>d[i].X1>>d[i].Y1;
        A+= (d[i].X1-d[i].X0) * (d[i].Y1-d[i].Y0);
        P+= 2*(d[i].X1-d[i].X0 + d[i].Y1-d[i].Y0);
    }
    for(int i=1; i<=2; i++)
        for(int j=i+1; j<=3; j++)
        {

            ariecom2(d[i],d[j]);
            A-=a;
            P-=p;
        }
    ariecom3(d[1],d[2],d[3]);
    A+=a;
    P+=p;
    g<<A<<' '<<P;
    return 0;
}