liyuzhe456 @ 2024-04-06 20:57:32
#include<bits/stdc++.h>
using namespace std;
int a[1001];
int main(){
int n,k;
cin>>n>>k;
int x,y;
int s=0;
for(int i=1;i<=k;i++){
cin>>x>>y;
for(int j=x;j<=y;j++){
a[j]=1;
}
}
for(int i=1;i<=n;i++){
if(a[i]==0) s++;
}
cout<<s;
return 0;
}
by Dream_Creator @ 2024-04-06 21:00:29
@li_yuzhe
求关注
(1)数组开小了,所以会 RE\ (2)左端点是 0
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main(){
int n,k;
cin>>n>>k;
int x,y;
int s=0;
for(int i=1;i<=k;i++){
cin>>x>>y;
for(int j=x;j<=y;j++){
a[j]=1;
}
}
for(int i=0;i<=n;i++){
if(a[i]==0) s++;
}
cout<<s;
return 0;
}
by liyuzhe456 @ 2024-04-06 21:02:59
@Dream_Creator 感谢!关注了奥!