题解 | 剩下的树
#include<iostream>
using namespace std;
int main(){
int L,M;
cin>>L;
cin>>M;
int low,high;
int trees[L+1];
for(int i=0;i<L+1;i++){
trees[i]=1;
}
while(M){
cin>>low>>high;
for(int i=low;i<=high;i++){
trees[i]=0;
}
M--;
}
int sum=0;
for(int i=0;i<L+1;i++){
sum+=trees[i];
}
cout<<sum<<endl;
}
查看13道真题和解析