GarfieldSHIT @ 2024-11-26 20:18:59
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,ans=0,x,y;
cin>>a>>b;
int tree[a-1];
for (int i=0; i<a-1; i++) tree[i]=-1;
for (int i=0; i<b; i++){
cin>>x>>y;
for (int j=x; j<y; j++) tree[j]=1;
}
for (int i=0; i<a-1; i++) if (tree[i]==-1) ans+=1;
cout<<ans;
return 0;
}
by yexiaotiao @ 2024-11-26 20:49:37
你可以试着换一个思路
by yexiaotiao @ 2024-11-26 20:56:39
虽然我不知道你那错了... 我也是个新手哈哈哈
by yexiaotiao @ 2024-11-26 20:57:18
这只是我的想法
by yexiaotiao @ 2024-11-26 21:00:40
我把前面删了,私发给你
by xmh_fd @ 2024-11-30 09:11:41
#include<bits/stdc++.h>
using namespace std;
int l,q,a[10010],ans;
int main(){
cin>>l>>q;
for(int i=1;i<=q;i++){
int x,y;
cin>>x>>y;
for(int j=x;j<=y;j++)a[j]=1;
}
for(int i=0;i<=l;i++){
if(!a[i])ans++;
}
cout<<ans;
return 0;
}