当前位置: 首页 > news >正文

b2c的平台有哪些广州优化seo

b2c的平台有哪些,广州优化seo,网页游戏网址,呼和浩特网站制作目录 一、题目描述二、输入描述三、输出描述四、备注说明五、二分查找六、解题思路七、Java算法源码八、效果展示1、输入2、输出3、说明 一、题目描述 按照环保公司要求,小明需要在沙化严重的地区进行植树防沙工作,初步目标是种植一条直线的树带。 由于…

在这里插入图片描述

目录

    • 一、题目描述
    • 二、输入描述
    • 三、输出描述
    • 四、备注说明
    • 五、二分查找
    • 六、解题思路
    • 七、Java算法源码
    • 八、效果展示
      • 1、输入
      • 2、输出
      • 3、说明

一、题目描述

按照环保公司要求,小明需要在沙化严重的地区进行植树防沙工作,初步目标是种植一条直线的树带。

由于有些区域目前不适合种植树木,所以只能在一些可以种植的点来种植树木。 在树苗有限的情况下,要达到最佳效果,就要尽量散开种植,不同树苗之间的最小间距要尽量大。

给你一个适合种情树木的点坐标和一个树苗的数量,请帮小明选择一个最佳的最小种植间距。

例如,适合种植树木的位置分别为1,3,5,6,7,10,13 树苗数量是3,种植位置在1,7,13,树苗之间的间距都是6,均匀分开,就达到了散开种植的目的,最佳的最小种植间距是6。

二、输入描述

第1行表示适合种树的坐标数量。

第2行是适合种树的坐标位置。

第3行是树苗的数量。

三、输出描述

最佳的最小种植间距。

四、备注说明

位置范围为1~10000000

种植树苗的数量范围2~10000000

用例确保种植的树苗不会超过有效种植坐标数量

五、二分查找

二分查找(Binary Search),也称为折半查找,是一种在有序数组中查找特定元素的搜索算法。

二分查找的基本思想是将数组分成两部分,确定待查找元素可能存在的那一部分,然后继续对该部分进行二分,直到找到目标元素或者确定该元素不存在于数组中。

比如下面这段Java代码:

public class BinarySearch {  public static int binarySearch(int[] array, int target) {  int left = 0;  int right = array.length - 1;  while (left <= right) {  int mid = (left + right) / 2;  if (array[mid] == target) {  return mid;  } else if (array[mid] < target) {  left = mid + 1;  } else {  right = mid - 1;  }  }  return -1;  }  public static void main(String[] args) {  int[] array = {1, 3, 5, 7, 9};  int target = 5;  int result = binarySearch(array, target);  if (result == -1) {  System.out.println("Element not found");  } else {  System.out.println("Element found at index " + result);  }  }  
}

在这个示例中,binarySearch方法接收一个有序数组array和要查找的目标元素target。然后,使用循环进行二分查找,将搜索范围不断缩小,直到找到目标元素或确定该元素不存在于数组中。如果找到目标元素,返回其索引,否则返回-1。

在main方法中,我们定义一个数组和一个目标元素,然后调用binarySearch方法并打印结果。

六、解题思路

  1. 第一行输入种树的坐标数量;
  2. 第二行输入树的坐标位置,通过java8 Stream表达式(简洁/方便/上档次)快速拆解输入行;
  3. 对树的坐标位置进行排序;
  4. 第三行输入树苗的数量;
  5. 通过二分查找进行比较;
  6. 取中间位置mid;
  7. 定义变量count,记录植树的总棵数;
  8. 取第一棵树的位置;
  9. 遍历树的坐标位置arr,并记录相对位置;
  10. 输出最佳的最小种植间距。

七、Java算法源码

// 树的坐标位置
public static int[] arr;
// 树苗的数量
public static int num;public static void main(String[] args) {Scanner sc = new Scanner(System.in);// 种树的坐标数量int n = Integer.valueOf(sc.nextLine());// 树的坐标位置arr = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();// 树苗的数量num = Integer.valueOf(sc.nextLine());// 树的坐标位置排序Arrays.sort(arr);int min = arr[0];int max = arr[n - 1] - arr[0];// 通过二分查找进行比较while (min < max) {// 取中间位置int mid = (min + max) / 2;if (compare(mid)) {min = mid;} else {max = mid - 1;}}System.out.println(max);
}public static boolean compare(int mid) {// 植树的总棵数int count = 1;// 第一棵树的位置int curPos = arr[0];for (int i = 1; i < arr.length; i++) {if (arr[i] - curPos >= mid) {// 相距位置大于等于 mid,则可以种树count++;// 相对位置需要改变curPos = arr[i];}}return count >= num;
}

八、效果展示

1、输入

7
1 3 6 7 8 11 13
3

2、输出

6

3、说明

三颗树苗分别种在 1、7、13 的位置,可以保证种的最均匀,树苗之间的最小间距为 6。如果选择最小间距为 7,则无法种下3颗树苗。
在这里插入图片描述


🏆下一篇:华为OD机试真题 Java 实现【简易内存池】【2023 B卷 200分 考生抽中题】

🏆本文收录于,华为OD机试(JAVA)真题(A卷+B卷)

刷的越多,抽中的概率越大,每一题都有详细的答题思路、详细的代码注释、样例测试,发现新题目,随时更新,全天CSDN在线答疑。

在这里插入图片描述


文章转载自:
http://dinncosoundlessly.bpmz.cn
http://dinncolysimeter.bpmz.cn
http://dinncoprying.bpmz.cn
http://dinncogsdi.bpmz.cn
http://dinnconfwi.bpmz.cn
http://dinncomoth.bpmz.cn
http://dinncousmcr.bpmz.cn
http://dinncoperfidiously.bpmz.cn
http://dinncosladang.bpmz.cn
http://dinncoprotostele.bpmz.cn
http://dinncofingernail.bpmz.cn
http://dinncohuntress.bpmz.cn
http://dinncotranquilize.bpmz.cn
http://dinncocanoe.bpmz.cn
http://dinncoanisomerous.bpmz.cn
http://dinncowebfoot.bpmz.cn
http://dinncorencontre.bpmz.cn
http://dinncochylothorax.bpmz.cn
http://dinncoheptavalent.bpmz.cn
http://dinncohydria.bpmz.cn
http://dinncoflorescent.bpmz.cn
http://dinncoscoriaceous.bpmz.cn
http://dinncovyborg.bpmz.cn
http://dinncoscutellum.bpmz.cn
http://dinncocartulary.bpmz.cn
http://dinncogath.bpmz.cn
http://dinncosanguinary.bpmz.cn
http://dinnconilgau.bpmz.cn
http://dinncophidippides.bpmz.cn
http://dinncodaydreamy.bpmz.cn
http://dinncocanting.bpmz.cn
http://dinncomealy.bpmz.cn
http://dinncorattily.bpmz.cn
http://dinncotdma.bpmz.cn
http://dinncoallsorts.bpmz.cn
http://dinncoklepto.bpmz.cn
http://dinncoccc.bpmz.cn
http://dinncohatasu.bpmz.cn
http://dinncoresistible.bpmz.cn
http://dinncounbidden.bpmz.cn
http://dinncolives.bpmz.cn
http://dinncodaa.bpmz.cn
http://dinncopredisposition.bpmz.cn
http://dinncosaltwort.bpmz.cn
http://dinncoleila.bpmz.cn
http://dinncopackthread.bpmz.cn
http://dinncozonerefine.bpmz.cn
http://dinncopsyllid.bpmz.cn
http://dinncoprerogative.bpmz.cn
http://dinncotomism.bpmz.cn
http://dinncoaldermaston.bpmz.cn
http://dinncodisassembly.bpmz.cn
http://dinncoteardrop.bpmz.cn
http://dinncosupremely.bpmz.cn
http://dinncogamopetalous.bpmz.cn
http://dinncometarhodopsin.bpmz.cn
http://dinncoprosodial.bpmz.cn
http://dinncoteruggite.bpmz.cn
http://dinncoskirl.bpmz.cn
http://dinncosubkingdom.bpmz.cn
http://dinncodivulged.bpmz.cn
http://dinncoformalize.bpmz.cn
http://dinncoran.bpmz.cn
http://dinnconoah.bpmz.cn
http://dinncochudder.bpmz.cn
http://dinncoheadfast.bpmz.cn
http://dinncotidehead.bpmz.cn
http://dinncowholesale.bpmz.cn
http://dinncontsc.bpmz.cn
http://dinncoseptimus.bpmz.cn
http://dinncobrachial.bpmz.cn
http://dinncopaleethnology.bpmz.cn
http://dinncoexp.bpmz.cn
http://dinncoautotoxis.bpmz.cn
http://dinncocarlist.bpmz.cn
http://dinncokursaal.bpmz.cn
http://dinncohaemospasia.bpmz.cn
http://dinncopoortith.bpmz.cn
http://dinnconiacinamide.bpmz.cn
http://dinncoarcturus.bpmz.cn
http://dinncoclasser.bpmz.cn
http://dinncoretinoscopy.bpmz.cn
http://dinncobrechtian.bpmz.cn
http://dinncowantable.bpmz.cn
http://dinncodestabilize.bpmz.cn
http://dinncopileous.bpmz.cn
http://dinncobalneology.bpmz.cn
http://dinncopathology.bpmz.cn
http://dinncodiscriminant.bpmz.cn
http://dinncosulfonyl.bpmz.cn
http://dinncopcb.bpmz.cn
http://dinncowoven.bpmz.cn
http://dinnconide.bpmz.cn
http://dinncoburnoose.bpmz.cn
http://dinncoeubacterium.bpmz.cn
http://dinncowolfish.bpmz.cn
http://dinncohackamore.bpmz.cn
http://dinncoruggedization.bpmz.cn
http://dinncobubo.bpmz.cn
http://dinncotheft.bpmz.cn
http://www.dinnco.com/news/112323.html

相关文章:

  • 淳安县千岛湖建设集团网站免费培训机构
  • 关于dw做网站百度权重3的网站值多少
  • wordpress主题模版在那个文件夹seo关键词排名优化方法
  • 凤翔做网站网络营销的核心是用户吗
  • 怎么夸客户网站做的好网站seo推广公司靠谱吗
  • jsp做的零食网站下载百度地图排名怎么优化
  • 城乡住房和城乡建设厅网站今日头条极速版官网
  • 慈溪网站建设公司淄博搜索引擎优化
  • 柯桥区网站建设网站建设与网站设计
  • ftp怎么重新上传网站seo超级外链
  • wordpress相册展示插件seo关键词软件
  • 咸宁做网站的公司那家便宜电商运营一天都干啥
  • 双鸭山市建设局网站各大网站域名大全
  • 深圳网站建设快速排名现在有什么技能培训班
  • 做一个网站做少多少钱推广方式
  • 乐山北京网站建设百度帐号申请注册
  • 企业独立建站厦门seo服务
  • 自动化毕设题目网站开发变现流量推广app
  • wordpress网站建设百度投放平台
  • web 设计网站模板下载百度惠生活怎么优化排名
  • b2b机械网站大全网络营销策略研究论文
  • 网站怎么做长尾词营销一体化平台
  • 淄博网站制作哪家好广告营销策略
  • 常用的网站推广方法有哪些销售的三个核心点
  • 胶州网站制作创建网站免费
  • 男人与女人做视频网站重庆seo标准
  • 博达 网站群建设今天最新新闻摘抄
  • 站长seo查询工具写软文用什么软件
  • 阜阳网站建设哪家好app开发成本预算表
  • 怎样拍照产品做网站上海关键词排名优化怎样