King_and_Grey @ 2024-05-28 17:11:54
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,k,ans;
bool isok[100000];
struct node{
int begin,end;
}a[105];
signed main(){
cin >> n >> k;
memset(isok,true,sizeof(isok));
for (int i = 1; i <= k; i++){
cin >> a[i].begin >> a[i].end;
}
for(int i = 1; i <= k; i++){
for(int j = a[i].begin; j <= a[i].end ;j++){
if(isok[j] == true){
isok[j] = false;
}
}
}
for(int i = 1; i <= n ;i++){
if(isok[i] == true){
ans++;
}
}
cout << ans + 1 << endl;
return 0;
}
我不懂!!! 明明我考虑了左端点从一开始的情况
by George_gmj @ 2024-06-01 15:30:28
6 洛谷炸了
by wjz0000000 @ 2024-06-16 13:27:58
这样就行了```
using namespace std; int main(){ int a,b,c,d,f; cin>>a>>b; int e[a+1]; for(int i=0;i<a+1;i++){ e[i]=0; } for(int i=0;i<b;i++){ cin>>c>>d; for(int j=c;j<=d;j++){ e[j]=1;
}
}for(int i=0;i<a+1;i++){
if(e[i]==0){
f+=1;
}
}cout<<f;
}