xiaoyu_mc @ 2024-10-04 02:52:15
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int l, m, u[100], v[100], result, tree[10000], temp;
cin>>l>>m;
temp=l;
while (temp>=0){
tree[temp]=1;
temp--;
}
while (m>0){
cin>>u[m]>>v[m];
for (temp=u[m];temp<=v[m];temp++){
tree[temp]=0;
}
m--;
}
while (l>=0){
if (tree[l] == 1){
result++;
}
l--;
}
cout<<result;
return 0;
}
头两个爆红了 求大佬指教
by Lisuyang @ 2024-10-04 07:25:51
@xiaoyu_mc
#include <iostream>
using namespace std;
int a[10006];
int main(){
int L, M, x, y, sum = 0;
scanf("%d%d", &L, &M);
for(int i = 1; i <= M; ++ i){
scanf("%d%d", &x, &y);
for(int j = x; j <= y; ++ j){
if(a[j] == 0)
a[j] = 1;
}
}
for(int i = 0; i <= L; ++ i){
if(a[i] == 0)
++ sum;
}
printf("%d", sum);
return 0;
}