解题思路:利用布尔数组
注意事项:
参考代码:
package arrLast; //题目 1099: 校门外的树 import java.util.Scanner; public class t_1099 { public static void main(String args []) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); boolean []arr=new boolean[n+1];//因为假如输入10,那么是有0-10所以有11个树坑; int m=sc.nextInt(); while(m!=0) { int x=sc.nextInt();//输入区间 int y=sc.nextInt(); for(int i=x;i<=y;i++) {//如果在区间内标记为true arr[i]=true; }m--; } int cont=0; for(int i=0;i<=n;i++) { if(!arr[i])//要是为flase那么就是有树为了符合条件所以用‘!’ cont++; } System.out.println(cont); } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:521 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:451 |
用筛法求之N内的素数。 (C语言代码)浏览:803 |
1011题解浏览:761 |
1024题解浏览:806 |
模拟计算器 (C语言代码)浏览:2299 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:800 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:382 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:685 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:527 |