标签:
#include<stdio.h> const int maxn=10000; int main(){ int n=0, m=0; while(scanf("%d %d", &n, &m) != EOF){ int cnt=0; int trees[maxn]={0};//保存路旁的树,0代表有树,1代表没树 for(int i=0; i < m; i++){ int up, low;//砍树区间的上界和下界 scanf("%d %d", &low, &up); for(int j=low; j <= up; j++){ trees[j]=1; } }//砍树结束,开始计数 for(int i=0; i <= n; i++){ if(trees[i] == 0) cnt++; } printf("%d\n", cnt); } return 0; }
标签:
原文地址:http://www.cnblogs.com/dudu-bird/p/5197800.html