题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include <stdio.h> int main() { int L, M; while (scanf("%d%d", &L, &M) != EOF) { int road[10001]; for (int i = 0; i <= L; i++) { road[i] = 1; } for (int q = 0; q < M; q++) { int left, right; scanf("%d%d", &left, &right); for (int i = left; i <= right; i++) { road[i] = 0; } } int sum = 0; for (int j = 0; j <= L; j++) { if (road[j] == 1) { sum++; } } printf("%d", sum); } return 0; }