I_love_big_ba_lei_te @ 2024-08-09 12:58:23
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,sum=0;
cin>>a>>b;
int q,w;
int s[a+2];
for(int i=1;i<=a;i++)
s[i]=0;
for(int i=1;i<=b;i++)
{
cin>>q>>w;
for(int i=q;i<=w;i++)
{
if(s[i]==0)
s[i]=1;
}
}
for(int i=1;i<=a;i++)
if(s[i]==0)
sum++;
cout<<sum;
return 0;
}
by XiaoHongChong @ 2024-08-09 13:05:23
@zhangdongzhe
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,sum=0;
cin>>a>>b;
int q,w;
int s[a+2] = {0}; //要初始化
for(int i=1;i<=a;i++)
s[i]=0;
for(int i=1;i<=b;i++)
{
cin>>q>>w;
for(int i=q;i<=w;i++)
{
if(s[i]==0)
s[i]=1;
}
}
for(int i=0;i<=a;i++) //是从0开始的
if(s[i]==0)
sum++;
cout<<sum;
return 0;
}
by qw0er2ty1ui3 @ 2024-08-09 13:30:16
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,sum=0;
cin>>a>>b;
int q,w;
int s[a+2];
for(int i=0;i<=a;i++)
s[i]=0;
for(int i=0;i<=b;i++)
{
cin>>q>>w;
for(int i=q;i<=w;i++)
{
if(s[i]==0)
s[i]=1;
}
}
for(int i=0;i<=a;i++)
if(s[i]==0)
sum++;
cout<<sum;
return 0;
}
by qw0er2ty1ui3 @ 2024-08-09 13:30:37
@zhangdongzhe
by IaLWH @ 2024-08-09 13:31:44
@XiaoHongChong 话说他的第一个for循环不是初始化吗
by XiaoHongChong @ 2024-08-09 14:39:52
@IaLWH 是啊,我和他的代码都能初始化
by I_love_big_ba_lei_te @ 2024-08-28 14:27:54
@XiaoHongChong 谢了
by XiaoHongChong @ 2024-08-28 17:25:31
@zhangdongzhe 不用谢