#include <stdio.h>
#define MAX 2000
int Intersection(int a,int b,int a1,int b1){
if(a<=a1&&b>=b1)
return b1-a1;
else if(a>=a1&&b<=b1)
return b-a;
else if((a>=a1&&a<=b1)&&b>=b1)
return b1-a;
else if(a<=a1&&(b<=b1&&b>=a1))
return b-a1;
else
return 0;
}
int main(){
int n,i,j,time=0,a,b;
int time_beg[MAX],time_end[MAX];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d",&time_beg[i],&time_end[i]);
}
for(i=0;i<n;i++){
scanf("%d%d",&a,&b);
for(j=0;j<n;j++)
time+=Intersection(a,b,time_beg[j],time_end[j]);
}
printf("%d\n",time);
return 0;
}
CCF-买菜(201809-2)-C语言(100分)
最新推荐文章于 2021-05-24 10:04:35 发布