题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include <iostream>
#include<vector>
using namespace std;
int main() {
int L, M, boxmin, boxmax,n = 1;
cin >> L >> M;
std::vector<int>tree(L, 1);
while (M > 0) {
cin >> boxmin >> boxmax;
for(int i = boxmin-1;i<boxmax;++i){
tree[i]=0;
}
M--;
}
for(int j = 0;j<L;j++){
if(tree[j]==1){
n+=1;
}
}
std::cout<<n<<std::endl;
}
查看8道真题和解析