@[圣啦啦](/user/241649) 统计的是种了树的位置,不是没种树的位置
by A_Đark_Horcrux @ 2020-02-09 10:14:10
```
#include<iostream>
#include<cstdio>
using namespace std;
const int N=10005;
bool a[N];
int main(){
a[N]={1};
int l,n;
scanf("%d%d",&l,&n);
for(int i=0;i<n;i++){
int b,c;
scanf("%d%d",&b,&c);
for(int j=b;j<=c;j++){
if(a[j]){
a[j]=0;
}
}
}
int tot=0;
for(int i=0;i<l;i++){
if(a[i]){
tot++;
}
}
printf("%d",tot);
return 0;
}
```
@[A_Dark_Horcrux](/user/54372)
by 圣啦啦 @ 2020-02-09 10:20:07
@[A_Dark_Horcrux](/user/54372)
输出了一个0,求助解答...
by 圣啦啦 @ 2020-02-09 10:20:37
@[圣啦啦](/user/241649)
1.a数组不要那么赋初值
2.统计时从0到L,不是从0到L-1
```cpp
//AC
#include<iostream>
#include<cstdio>
using namespace std;
const int N=10005;
bool a[N];
int main(){
int l,n;
scanf("%d%d",&l,&n);
for(int i=0;i<=l;++i){//循环赋初值
a[i]=1;
}
for(int i=0;i<n;i++){
int b,c;
scanf("%d%d",&b,&c);
for(int j=b;j<=c;j++){
if(a[j]){
a[j]=0;
}
}
}
int tot=0;
for(int i=0;i<=l;i++){//不是从0到L-1
if(a[i]){
tot++;
}
}
printf("%d",tot);
return 0;
}
```
by Barry_Wang @ 2020-02-09 10:31:56
@[_barry·wang_](/user/25004)
哦哦,明白了,少了个等号,膜拜感谢大神!!!
by 圣啦啦 @ 2020-02-09 10:37:10