zhaomy @ 2024-09-28 20:38:05
#include <bits/stdc++.h>
using namespace std;
int main(){
int len;
cin>>len;
int times;
cin>>times;
int ha[10005];
for(int i = 1;i<=len;i++){
ha[i] = 1;
}
int sum = len;
for(int i = 0;i<times;i++){
int l,r;
cin>>l>>r;
for(int j = l;j<=r;j++){
if(ha[j] == 1){
sum--;
ha[j] = 0;
}
}
}
cout<<sum;
return 0;
}
by zhaomy @ 2024-09-28 20:38:33
求大佬指导
by Deric456 @ 2024-09-28 20:42:54
#include<bits/stdc++.h>
using namespace std;
int main(){
int length,m,sum=0;
cin>>length>>m;
int arr[length+1];
for(int i=0;i<=length+1;i++){
arr[i]=1;
}
int l,r;
for(int i=1;i<=m;i++){
cin>>l>>r;
for(int j=l;j<=r;j++){
arr[j]=0;
}
}
for(int i=0;i<=length+1;i++){
if(arr[i]==1){
sum++;
}
}
cout<<sum-1;
return 0;
}
AC代码求关
by Deric456 @ 2024-09-28 20:43:08
@zhaomy
by zhaomy @ 2024-09-28 20:46:38
@Deric456 谢谢大佬