BenChaut @ 2022-10-22 18:13:09
#include <stdio.h>
int main()
{
int arr[100000] = { 0 };
int l = 0, n = 0;
scanf("%d %d", &l, &n);
for (int i = 0; i < l; i++)
{
arr[i] = i;
}
for (int j = 0; j < n; j++)
{
int a, s;
scanf("%d %d", &a, &s);
for (a; a <= s; a++)
{
if (arr[a] != 0)
{
arr[a] = 0;
l--;
}
}
a = 0;
s = 0;
}
printf("%d", l+1);
return 0;
}
by Ja50nY0un9_as_AgNO3 @ 2022-10-22 18:15:43
@BenChaut 注意,位置0也有一棵树。应该把arr全部初始化为非0值,否则砍第0棵树时会出问题。
by Ja50nY0un9_as_AgNO3 @ 2022-10-22 18:16:12
@BenChaut 另外,位置