@[谭倓](/space/show?uid=135426)
```cpp
for(int i=0;i<l;i++)
```
改成
```cpp
for(int i=0;i<=l;i++)
```
最后输出的时候不用加 1 。
by Drinkkk @ 2019-05-11 21:56:25
@[钟梓俊](/space/show?uid=48269) 已经AC了,谢谢~
by 谭倓 @ 2019-05-11 21:58:55
@[钟梓俊](/space/show?uid=48269)
by LT123456 @ 2019-05-12 01:41:57
@[钟梓俊](/space/show?uid=48269)
大佬你好,有道题我纠结了很长时间了[P1047 校门外的树],但是由于注册没满七天,所以想发帖问别人都不行,所以就来问您了,我这个代码到底哪里有问题啊?您能帮我看看吗?
这道题我的思路是只要某一点的坐标不在移走树的区域内(起始点到终止点之间)即为剩下的树,而判断方法为只要坐标小于起始点或大于终止点,就说明不在该区域内,把M个区域循环一次,如果对于所有的移树区域都满足小于起始点或大于终止点,则该坐标的树是留下的树,从0到L循环一遍,即可得到总的留下的树,但是我的代码运行结果却一直错误,我怎么都不知道哪里出错了,恳请大佬帮忙看看,谢谢了!
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,a[300],k,b,c=0,d=0,t;
cin>>i;
cin>>j;
for(k=0;k<=(2*j-1);k++)
{cin>>a[k];}
for(t=0;t<=i;t++)
{for(b=0;b<=(2*j-2);b=b+2)
{
if(t<a[b]||t>a[b+1])
{
c++;
}}
if(c==j)
{
d++;
}}
printf("%d",d);
return 0;
}
```
by LT123456 @ 2019-05-12 01:52:48
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
int m, i, s = 0, l, x, y, j;
cin >> l >> m;
for (i = 0; i <= l; i++)
a[i] = 1;
for (i = 1; i <= m; i++)
{
cin >> x >> y;
for (j = x; j <= y; j++)
{
a[j] = 0;
}
}
for (i = 0; i <= l; i++)
if (a[i] == 1) s++;
cout << s << endl;
return 0;
}
这道题可以用一位数组,挺方便的呀
by 沧海 @ 2019-05-12 11:13:25
@[LT123456](/space/show?uid=208975) 您的 $c$ 要清 0 。
即将
```cpp
for(t=0;t<=i;t++)
{for(b=0;b<=(2*j-2);b=b+2)
```
改为
```cpp
for(t=0;t<=i;t++)
{c=0;for(b=0;b<=(2*j-2);b=b+2)
```
by Drinkkk @ 2019-05-13 19:08:23
@[钟梓俊](/space/show?uid=48269) 哈哈谢了,@完你后我就发现了
by LT123456 @ 2019-05-14 10:18:16