模拟,但是需要注意的细节比较多, (也可能是我晚上脑子不清醒了…),反正就是题不难,但是要注意细节
AcWing 1749. 阻挡广告牌 II
#include<bits/stdc++.h>
using namespace std;
const int N = 2010;
int x[4], y[4];
int r1, c1;//第一个的长宽
int r2, c2;//第二个的长宽
int g[N][N];//染色布
int main()
{
cin>>x[0]>>y[0]>>x[1]>>y[1]; //记录第一个牌,割草机
cin>>x[2]>>y[2]>>x[3]>>y[3]; //记录第二个牌,饲料牌
r1 = x[1] - x[0];
c1 = y[1] - y[0];
r2 = x[3] - x[2];
c2 = y[3] - y[2];
int s = r1 * c1; //记录割草机牌子面积
int s2 = r2 * c2;
if(x[0] >= x[2] && x[1] <= x[3] && y[0] >= y[2] && y[1] <= y[3]){ //全覆盖
cout<<0<<endl; //全覆盖
}
else if(x[0] >= x[2] && x[1] <= x[3]){ //横向对齐或覆盖
if(y[3] >= y[0] && y[2] <= y[1]){ //有交集
if(y[3] <= y[1] && y[2] >= y[0]){ //中覆盖
cout<<s<<endl;
}
else if(y[3] >= y[1] && y[2] >= y[0]){ //上覆盖
int iu = y[1] - y[2];
cout<<s - iu * (x[1] - x[0]);
}
else{ //下覆盖
int iu = y[3] - y[0];
cout<<s - iu * (x[1] - x[0]);
}
}
else{
cout<<s<<endl; //没有交集
}
}
else if(y[0] >= y[2] && y[1] <= y[3]){ //纵向对齐或覆盖
if(x[2] <= x[1] && x[3] >= x[0]){
if(x[3] <= x[1] && x[2] >= x[0]){ //中覆盖
cout<<s<<endl;
}
else if(x[3] <= x[1] && x[2] <= x[0]){ //左覆盖
int iu = x[3] - x[0];
cout<<s - iu * (y[1] - y[0]);
}
else{ //右覆盖
int iu = x[1] - x[2];
cout<<s - iu * (y[1] - y[0]);
}
}
else{
cout<<s<<endl; //没有交集
}
}
else{
cout<<s<<endl;
}
return 0;
}