题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include<cstdio> int main() { int tree[10001]; int L, M ; scanf("%d%d", &L, &M); for (int i = 0; i <= L; ++i) { tree[i] = 1; } for (int idx = 0; idx < M; ++idx) { //外部循环可以用无关字母 int left, right; scanf("%d%d", &left, &right); for (int i = left; i <= right; ++i) { tree[i] = 0; } } int rem = 0; for (int i = 0; i <= L; ++i) { if (tree[i] == 1) { ++rem; } } printf("%d\n", rem); }