mioter @ 2023-02-01 19:59:51
大佬们,这样只有第一个正确,结果+1后前两个不对,球球帮忙看一下
#include <stdio.h>
#define NO -1
int main(){
int L[10001] = {NO};
int m = 0, n = 0, num = 0;
scanf("%d %d",&m,&n);
for ( int i = 0; i < n; i++){
int a = 0, b = 0;
scanf("%d %d",&a,&b);
for (; a <= b; a++){
L[a] = 1;
}
}
for (int i = 1; i <= m; i++){
printf("L[%d] = %d\t",i,L[i]);
if ( L[i] == 0) num++;
}
printf("%d",num);
}
by zzs2731 @ 2023-02-01 20:09:31
#include<bits/stdc++.h>
using namespace std;
int main(){
int m[10005]={},l,x,n,a,b,ans=0;
cin>>l>>x;
for(n=1;n<=x;n++){
cin>>a>>b;
for(a=a;a!=b+1;a++){
m[a]=1;
}
}
for(n=0;n<=l;n++){
if(m[n]==1){
ans=ans+1;
}
}
l=l-ans;
cout<<l+1;
return 0;
}
by shuiren @ 2023-02-01 20:37:47
最后统计的时候是从零开始,你没算上
by mioter @ 2023-02-02 17:22:19
@shuiren 太傻了,没看到。现在已经解决了,谢谢大佬