#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,n,i,sum=0;
scanf("%d %d %d",&n,&a,&b);
int x1[n],y1[n],x2[n],y2[n];
for(i=0;i<n;i++){
scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
if(x1[i]<0)
x1[i]=0;
if(x1[i]>a)
x1[i]=a;
if(y1[i]<0)
y1[i]=0;
if(y1[i]>b)
y1[i]=b;
if(x2[i]<0)
x2[i]=0;
if(x2[i]>a)
x2[i]=a;
if(y2[i]<0)
y2[i]=0;
if(y2[i]>b)
y2[i]=b;
}
for(i=0;i<n;i++){
sum+=(x2[i]-x1[i])*(y2[i]-y1[i]);
}
printf("%d",sum);
return 0;
}
只需要大家根据例子画一个图,就能明白,只要将输入的数据限制在边框里:
大于边就设为边(记得区分长宽啊喂!),小于0就设为0就可以了!