题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include <stdio.h> #include<stdlib.h> int main() { int L, c; scanf("%d %d", &L, &c); int* arr = (int*)calloc(L + 1, sizeof(int)); while (c--) { // 注意 while 处理多个 case int low, high; scanf("%d %d", &low, &high); for (int i = low; i <= high; ++i) { arr[i] = 1; } } int cnt = 0; for (int i = 1; i <= L; ++i) { if (arr[i] == 0) { ++cnt; } } printf("%d", cnt + 1); return 0; }