解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class 种树 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
a += 1;
int b = sc.nextInt();
int c, d;
int sum = 0;
int arr[] = new int[a];
for (int i = 0; i < a; i++)
arr[i] = 1;
for (int i = 0; i < b; i++) {
c = sc.nextInt();
d = sc.nextInt();
for (int x = 0; x < a; x++) {
if (x <= d && x >= c)
arr[x] = 0;
}
}
for (int x = 0; x < a; x++) {
if (arr[x] == 1)
sum++;
}
System.out.print(sum);
}
}
0.0分
3 人评分