题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include<cstdio> int main(){ int n,m; scanf("%d%d",&n,&m); int tree[n]; for(int i = 0 ; i < n ;++i){ tree[i] = 1; } for(int idx = 0 ; idx < m ;++idx){ int left ,right ; scanf("%d%d",&left,&right); for(int i = left -1 ;i < right ;++i){ tree[i] = 0; } } int count =1; for(int i = 0 ; i < n ;++i){ if(tree[i] == 1){ ++count; } } printf("%d\n",count); }