Cc1537509875 @ 2024-09-08 19:46:47
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int n,m,ans=0;
cin>>n>>m;
bool a[n+5]={1};
for(int k=1;k<=m;k++){
int x,y;
cin>>x>>y;
for(int i=x;i<=y;i++){
a[i]=0;
}
}
for(int i=1;i<=n;i++){
if(a[i])ans++;
}
cout<<ans;
return 0;
}
by 违规用户名K&xs3Z^ @ 2024-09-08 19:52:35
@Cc1537509875 1.初始化有误 建议使用memset或者for 2.0端点也算 因此累加ans的for从 i=0 开始
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int n,m,ans=0;
cin>>n>>m;
bool a[n+5];
memset(a,1,sizeof a);
for(int k=1;k<=m;k++){
int x,y;
cin>>x>>y;
for(int i=x;i<=y;i++){
a[i]=0;
}
}
for(int i=0;i<=n;i++){
if(a[i])ans++;
}
cout<<ans;
return 0;
}
求关
by Cc1537509875 @ 2024-09-08 20:02:51
@违规用户名K&xs3Z^ 多谢已关