AcWing 1761. 阻挡广告牌
原题链接
简单
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e3+5;
int a[N][N];
int main(){
int x1,x2,y1,y2,max1=0;
for(int i=0;i<3;i++){
cin>>x1>>y1>>x2>>y2;
// x2和y2是每次区域的右上角坐标,则最大的坐标在其中产生,拿到最大的坐标值,方便最后遍历数组,避免没必要的循环
if(max(x2,y2)>max1)
max1 = max(x2,y2);
//下面代码中+1000是为了更好的利用数组下标,输入的数据范围是-1000~1000,会有负数坐标。
for(int j = x1+1000;j<x2+1000;j++){
for(int k=y1+1000;k<y2+1000;k++){
a[j][k] = i+1;
}
}
}
int ans=0;
for(int i=0;i<=max1+1000;i++){
for(int j=0;j<=max1+1000;j++){
if(a[i][j]==1 || a[i][j] == 2)
ans ++;
}
}
cout<<ans;
return 0;
}