题解 | #剩下的树#

剩下的树

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;
}

全部评论

相关推荐

HNU_fsq:建议直接出国,这简历太6了。自愧不如
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务