Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.7 kB
4
Indexable
Never
#include<stdio.h>
int area(int a, int b, int c, int d, int e, int f, int g, int h){
    int area = 0;
    for(int i = a; i < c; i++){
        for(int j = b; j < d; j++){
            if(i >= e && i < g && j >= f && j < h) area++;
        }
    }
    return area;
}
int area0(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l){
    int temp0 = 100000, temp1 = 100000, temp2 = 100000, temp3 = 100000, o;
    for(int i = a; i < c; i++)
        for(int j = b; j < d; j++){
            int m = a + c - i, n = b + d - j;
            if(m > e && m <= g && n > f && n <= h){
                temp0 = m-1;
                temp1 = n-1;
            }
            if(i >= e && i < g && j >= f && j < h){
                temp2 = i+1;
                temp3 = j+1;
            }
        }
    if(temp0+temp1+temp2+temp3 == 400000) o = 0;
    else o = area(temp0, temp1, temp2, temp3, i, j, k, l);
    return o;
}
int main(){
    int l1, b1, r1, t1, l2, b2, r2, t2, l3, b3, r3, t3;
    scanf("%d%d%d%d%d%d%d%d%d%d%d%d", &l1, &b1, &r1, &t1, &l2, &b2, &r2, &t2, &l3, &b3, &r3, &t3);
    int area1 = (r1-l1)*(t1-b1), area2 = (r2-l2)*(t2-b2), area3 = (r3-l3)*(t3-b3);
    int area12 = 0, area23 = 0, area13 = 0, area123 = 0;
    area12 = area(l1, b1, r1, t1, l2, b2, r2, t2);
    area23 = area(l2, b2, r2, t2, l3, b3, r3, t3);
    area13 = area(l1, b1, r1, t1, l3, b3, r3, t3);
    area123 = area0(l1, b1, r1, t1, l2, b2, r2, t2, l3, b3, r3, t3);
    int overlap_area = area1+area2+area3-area12-area13-area23+area123;
    //printf("%d %d %d %d %d %d %d\n", area1, area2, area3, area12, area13, area23, area123);
    printf("%d\n", overlap_area);
    return 0;
}