Nemo_ @ 2023-04-21 20:10:13
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int l,m,r=0;
cin>>l>>m;
int a[l+1];
memset(a,0,sizeof(a));
for(int i=0;i<m;i++)
{
int v,b;
cin>>v>>b;
for(int j=v;j<=b;j++)
{
a[j]=1;
}
}
for(int p=0;p<l;p++)
{
if(a[p]!=1)
{
r++;
}
}
cout<<r+1<<endl;
return 0;
}
by Sun_Email @ 2023-04-21 20:12:23
你
@Di_MX
by Nemo_ @ 2023-04-21 20:15:22
@Sun_Email 倒数第6行r+1算的是l处的树
by Sun_Email @ 2023-04-21 20:31:18
那万一
by Nemo_ @ 2023-04-26 18:12:26
@Sun_Email 不好意思啊,我们中考体育考试,教练被抽调走了,这两天没登洛谷,所以,l处的树没了咋办??? dalao求解
by Sun_Email @ 2023-04-26 20:11:35
@Di_MX
你循环把
by Sun_Email @ 2023-04-26 20:11:58
输出输
by Sun_Email @ 2023-04-26 20:12:38
AC代码:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int l,m,r=0;
cin>>l>>m;
int a[l+1];
memset(a,0,sizeof(a));
for(int i=0;i<m;i++)
{
int v,b;
cin>>v>>b;
for(int j=v;j<=b;j++)
{
a[j]=1;
}
}
for(int p=0;p<l;p++)
{
if(a[p]!=1)
{
r++;
}
}
cout<<r+1<<endl;
return 0;
}
by Sun_Email @ 2023-04-26 20:13:39
还有提醒一点: 不要把变量放进数组定义里
不要写
数组的量提前开好
by Nemo_ @ 2023-04-30 17:43:48
@Sun_Email 因为某些原因,又没上洛谷,谢谢
by Nemo_ @ 2023-04-30 17:52:08
代码是错的