两个整数L(1<=L<=10000)和M(1<=M<=100)。 接下来有M组整数,每组有一对数字。
可能有多组输入数据,对于每组输入数据,输出一个数,表示移走所有区间的树之后剩下的树的个数。
链接:https://www.nowcoder.com/questionTerminal/f5787c69f5cf41499ba4706bc93700a2 来源:牛客网 import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int changdu = scanner.nextInt(); int b = scanner.nextInt(); Set<Integer> set = new HashSet<Integer>(); for (int i = 0; i <= changdu; i++) { set.add(i); } for (int i = 0; i < b; i++) { int min = scanner.nextInt(); int max = scanner.nextInt(); for (int j = min; j <= max; j++) { set.remove(j); } } System.out.println(set.size()); } } }
原文:https://www.cnblogs.com/JAYPARK/p/10121705.html