import java.util.Scanner;
public class 校门外的树 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean[] l = new boolean[sc.nextInt()+1];//501棵树
int m = sc.nextInt(), ans = 0;
for (int i=0;i<l.length;i++) {
l[i] = true;
}
for(int i=1;i<=m;i++){
int start = sc.nextInt(), end = sc.nextInt();
for(int j = start; j <= end; j++)
l[j] = false;
}
for(int i = 0; i < l.length; i++) {//从前到后遍历,区间为true的,ans++
if (l[i] == true) {
ans++;
}
}
System.out.println(ans);
}
}
Java实现 洛谷 P1047 [NOIP2005 普及组] 校门外的树
最新推荐文章于 2022-02-24 23:10:28 发布