holypl @ 2023-10-22 15:08:51
#include<stdio.h>
int main() {
int l;
int m;
scanf("%d %d", &l, &m);
if (l>=1&&l<1e4&&m>=1&&m<=100) {
int head;
int end;
int arr[10010];
for(int i=0;i<=l;i++){
arr[i] = 0;
}
for (int i = 0; i < m; i++) {
scanf("%d %d", &head, &end);
for (int j = head; j <= end; j++) {
if (arr[j] == 0) {
arr[j] = 1;
}
}
}
int cnt = 0;
for (int i = 0; i <=l; i++) {
if (arr[i] == 0) {
cnt++;
}
}
printf("%d", cnt);
}
return 0;
}
by Steve_xh @ 2023-10-22 15:38:38
数组初始化要从1到m,因为你的数组是用来判断这个地方有没有种树的,不是看有几个区间种树
by holypl @ 2023-10-24 14:53:54
@Steve_xh 谢谢大佬 谢谢大佬