题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include <stdio.h> int main() { int l, m; int list1[10001]; scanf("%d %d", &l, &m); for (int j = 0 ; j <= l; j++) { list1[j] = 1; } for (int i = 0; i < m; i++) { int from, to; scanf("%d %d", &from, &to); for (int k = from; k <= to; k++) { list1[k] = 0; } } int treenum = 0; for (int i = 0; i <= l; i++) { if (list1[i] == 1) { treenum++; } } printf("%d", treenum); return 0 ; }