样例输入
4 10 10
0 0 5 5
5 -2 15 3
8 8 15 15
-2 10 3 15
样例输出
44
答题
首先写一个计算面积的函数,既然大小固定就省去了比较,然后是将在范围之外的矩阵给忽略掉,接下来将碰到的矩阵大小缩小为范围之内的,累加即可
#include <iostream>
using namespace std;
int getArea(int x1, int x2, int y1, int y2){
return (x2-x1)*(y2-y1);
}
int main(){
int n,a,b,area=0,x1,x2,y1,y2;
cin>>n>>a>>b;
while(n--){
cin>>x1>>y1>>x2>>y2;
if(x1>=a||y1>=b||x2<=0||y2<=0)
continue;
x1=x1<0?0:x1;
y1=y1<0?0:y1;
x2=x2>a?a:x2;
y2=y2>b?b:y2;
area+= getArea(x1, x2, y1, y2);
}
cout<<area;
}