#include
int main()
{
int n,l,m,s=0,a,b;
scanf("%d %d",&l,&n);
int t[l];
for(m=1;m<=l;m++)t[m]=1;
for(int i=1;i<=n;i++)
{scanf("%d %d",&a,&b);
for(int j=a;j<=b;j++)
t[j]=0;
}for(m=1;m<=l;m++)
s+=t[m];
printf("%d",s+1);
return 0;
}
不知道错哪,求解!
#include <iostream>
using namespace std;
int main()
{
bool a[10001];
int i,j,s,e,L,M,num=0;
cin >> L >> M;
for (i=0;i<=L;i++) a[i] = true; // 有树
for (i=0;i<M;i++){
cin >> s >> e;
for (j=s;j<=e;j++){
a[j] = false;
}
}
for (i=0;i<=L;i++)
if (a[i]) num++; // 统计
cout << num << endl;
return 0;
}
```c++
```
L米有L+1棵树