aa1939617614 @ 2023-11-29 00:29:10
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int l, m;
scanf("%d %d", &l, &m);
int a[l];
for (int i = 0; i < l + 1; i++)
{
a[i] = 1;
} // 初始化坐标的树,1为有,0为无
for (int i = 0; i < m; i++)
{
int begin, end;
scanf("%d %d", &begin, &end);
for (int i = begin; i < end + 1; i++)
{
a[i] = 0;
}
}
int n = 0;
for (int i = 0; i < l + 1; i++)
{
if (a[i] == 1)
{
n++;
}
}
printf("%d", n);
return 0;
}
by Luzhuoyuan @ 2023-11-29 08:13:15
@aa1939617614 a 数组定义改成 int a[l+1];
,因为 0~l 有 l+1 个元素。
by aa1939617614 @ 2023-12-04 00:34:45
@Luzhuoyuan ok谢谢大佬