题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include<bits/stdc++.h> #include<vector> using namespace std; int main() { int l;//马路的长度 int m;//M组整数 while (scanf("%d%d", &l, &m) != EOF) { int road[l + 1]; fill(road, road + l + 1, 0); for (int i = 0; i < m; i++) { int start; int end; scanf("%d%d", &start, &end); for (int j = start; j <= end; j++) { road[j] = 1; } } int count = 0; for (int i = 0; i < l + 1; i++) { if (road[i] == 0) count++; } printf("%d\n", count); } return 0; }