题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include <iostream> using namespace std; int main() { int L, M; bool tree[10000]; scanf("%d %d", &L, &M); // 初始化 0~L之间的所有树 for (int i = 0; i <= L; ++i) { tree[i] = true; } // 消除 区间树 for (; M > 0; --M) { // printf("%d %d", L, M); int begin, end; scanf("%d %d", &begin, &end); for (int i = begin; i <= end; ++i) { tree[i] = false; } } // 统计 0 ~ L 上还存在的树 int number = 0; for (int i = 0; i <= L; ++i) { if (tree[i] == true) { ++number; } } printf("%d\n", number); return 0; }