Cod sursa(job #1798192)

Utilizator andreicoman299Coman Andrei andreicoman299 Data 4 noiembrie 2016 22:00:24
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.72 kb
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define BUF_SIZE 16384
char buf[BUF_SIZE];
int pbuf=BUF_SIZE;
FILE*fi,*fo;
inline char nextch(){
    if(pbuf==BUF_SIZE){
        fread(buf, BUF_SIZE, 1, fi);
        pbuf=0;
    }
    return buf[pbuf++];
}
inline long long nextnum(){
    long long a=0;
    char c=nextch();
    while((c<'0' || c>'9') && c!='-')
        c=nextch();
    int semn=1;
    if(c=='-'){
        semn=-1;
        c=nextch();
    }
    while('0'<=c && c<='9'){
        a=a*10+c-'0';
        c=nextch();
    }
    return a*semn;
}

inline int min(int a, int b){
    return a < b ? a : b;
}
inline int max(int a, int b){
    return a > b ? a : b;
}

struct Rectangle{
    int x1, y1, x2, y2;
};
long long a(Rectangle R){
    return 1LL*(R.x2-R.x1)*(R.y2-R.y1);
}
long long p(Rectangle R){
    return 2LL*(R.x2-R.x1)+2LL*(R.y2-R.y1);
}
inline Rectangle intersect(Rectangle A, Rectangle B){
    Rectangle R;
    R.x1=max(A.x1, B.x1);
    R.y1=max(A.y1, B.y1);
    R.x2=min(A.x2, B.x2);
    R.y2=min(A.y2, B.y2);
    if(R.x1>R.x2 || R.y1>R.y2)
        R={0, 0, 0, 0};
    return R;
}

int main(){
    fi=fopen("reuniune.in","r");
    fo=fopen("reuniune.out","w");
    Rectangle A, B, C;
    fscanf(fi,"%d%d%d%d", &A.x1, &A.y1, &A.x2, &A.y2);
    fscanf(fi,"%d%d%d%d", &B.x1, &B.y1, &B.x2, &B.y2);
    fscanf(fi,"%d%d%d%d", &C.x1, &C.y1, &C.x2, &C.y2);
    fprintf(fo,"%lld ", a(A)+a(B)+a(C)-a(intersect(A, B))-a(intersect(B, C))-a(intersect(A, C))+a(intersect(A, intersect(B, C))));
    fprintf(fo,"%lld ", p(A)+p(B)+p(C)-p(intersect(A, B))-p(intersect(B, C))-p(intersect(A, C))+p(intersect(A, intersect(B, C))));
    fclose(fi);
    fclose(fo);
    return 0;
}