acDream


私信TA

用户名:acDream

访问量:32019

签 名:

欢迎光临CSDN博客https://blog.csdn.net/acDream_

等  级
排  名 138
经  验 7291
参赛次数 4
文章发表 72
年  龄 0
在职情况 学生
学  校 黑龙江工商学院
专  业 软件工程

  自我简介:

欢迎光临CSDN博客https://blog.csdn.net/acDream_

解题思路:有树的地方都设为1,没树设为0

注意事项:

参考代码:

package cWeb.buleCup;

import java.util.Scanner;
/**
 *	 未成功
 * 	@author Geek
 *	@version 1.0
 * 	@date 2018年6月28日 下午10:19:19
 *	@TextDemo I hava a acDream
 *	@copyright 
 *	@remark
 */
public class C1099 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int L = in.nextInt() + 1;
		int M = in.nextInt();
		int [] trees = new int [L];
		for (int i = 0; i < trees.length; i++) {
			trees[i] = 1;//1表示有树
		}
		for (int i = 0; i < M; i++) {
			int start = in.nextInt();
			int end = in.nextInt();
			for (int j = start; j < end+1; j++) {
				if(trees[j]==1) {
					trees[j] =0;
				}
			}	
		}
		int sum = 0;
		for (int i = 0; i < trees.length; i++) {
			if(trees[i]!=0) {
				sum++;
			}
		}
		System.out.println(sum);
		
	}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区