Description
有L+1个点,编号为[0,L],现在用M个区间覆盖这些点,问有多少点没有被覆盖。
Input
多组输入,每组的第一行有两个整数L(1 <= L <= 10000)和 M(1 <= M <= 100)
Output
每组数据输出一行,这一行只包含一个整数,表示没有被覆盖的点数。
Sample Input
500 3
150 300
100 200
470 471
Sample Output
298
思路:非常简单暴力地将输入区间内的值标记为0,最后在0到L中统计没有被标记为0的数组的个数
#include<stdio.h>
#include<string.h>
int main(){
int i,j,n,t,s,a,b,m,L;
while(scanf("%d%d",&L,&n)!=EOF){
int x[L+1];
memset(x,1,sizeof(x));
m=n;
while(n--){
scanf("%d%d",&a,&b);
for(i=a;i<=b;i++)//区间内标记为0
x[i]=0;
}
s=0;
for(i=0;i<=L;i++){//统计个数
if(x[i])
s++;
}
printf("%d\n",s);
}
return 0;
}