liangcha_crush_ly @ 2023-11-29 20:54:01
#include<bits/stdc++.h>
using namespace std;
int L,M,a[10010],ans,s,e;
int main(){
memset(a,0,sizeof(a));
cin>>M>>L;
for(int i=0;i<=L;i++)
a[i]=0;
for(int i=1;i<=M;i++){
cin>>s>>e;
for(int j=s;j<=e;j++){
a[j]=1;
}
}
for(int i=0;i<=L;i++){
if(a[i]==0)ans++;
}cout<<ans;
return 0;
}
by watergod @ 2023-11-29 21:04:00
@liangcha_crush 第6行,M和L输入顺序反了
by 2021zjhs005 @ 2023-11-29 21:19:24
@liangcha_crush
cin>>M>>L;
改成:
cin>>L>>M;
by liangcha_crush_ly @ 2023-11-29 21:45:50
@watergod 谢谢dalao
by zzlovequq @ 2023-12-01 16:27:29
有个问题 如果说输入的两个数s=100 e=200 在循环中不应该是int j=s-1(99),j<=e-1(199)吗 数组不是从0开始的吗
by zengyijian @ 2023-12-09 20:08:11
#include<iostream>
using namespace std;
bool a[10005];
int main() {
int l,m;
cin>>l>>m;
for(int i=0;i<=l;i++){
a[i]=1;
}
for(int i=1;i<=m;i++){
int b,c;
cin>>b>>c;
for(int j=b;j<=c;j++){
a[j]=0;
}
}
int cnt=0;
for(int i=0;i<=l;i++){
if(a[i]==1){
cnt++;
}
}
cout<<cnt;
return 0;
}