题解 | #剩下的树#
剩下的树
https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2
#include<iostream> using namespace std; const int MAXN =10001; int L,M; bool tree[MAXN]; int main(){ int h,l; while(scanf("%d %d",&L,&M)!=EOF) { for(int i=0;i<=L;i++){ tree[i]=true; } while(M--){ scanf("%d %d",&l,&h); for(int i=l;i<=h;i++) { tree[i]=false; } } int count=0; for(int i=0;i<=L;i++){ if(tree[i]==true){ count++; } } printf("%d\n",count); } }
简单题,不用想很高级的算法就可以完成