ACM-XZNU-1008 校门外的树 java 解题报告
500 3150 300100 200470 471
298import java.util.Scanner;
public class Main {public static void main(String[] args) {int L,n;int count = 0;Scanner sc = new Scanner(System.in); L = sc.nextInt(); n = sc.nextInt(); Boolean tree[] = new Boolean[L+1]; Integer space[][] = new Integer[n][2]; for (int k = 0; k < tree.length; k++) {tree[k] = true;} for (int i = 0; i < n; i++) {space[i][0] = sc.nextInt();space[i][1] = sc.nextInt();} for (int i = 0; i < n; i++) {int x = space[i][0];int y = space[i][1];for (int j = x; j <=y; j++) {tree[j] = false;}} for (int i = 0; i < tree.length; i++) { if(tree[i]==true)count++;} System.out.println(count);}}?这一题主要是利用一个boolean数组实现的很简单