当前位置: 首页 > 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://cupronickel.xzLp.cn
http://vasovasostomy.xzLp.cn
http://capercaillie.xzLp.cn
http://lunular.xzLp.cn
http://coadjustment.xzLp.cn
http://diastase.xzLp.cn
http://fierce.xzLp.cn
http://polyopia.xzLp.cn
http://ywha.xzLp.cn
http://gunmaker.xzLp.cn
http://aspersion.xzLp.cn
http://ambisonics.xzLp.cn
http://halogen.xzLp.cn
http://swinglebar.xzLp.cn
http://frenzy.xzLp.cn
http://patrolette.xzLp.cn
http://wed.xzLp.cn
http://complemental.xzLp.cn
http://hornpout.xzLp.cn
http://terraqueous.xzLp.cn
http://rustling.xzLp.cn
http://clifton.xzLp.cn
http://solely.xzLp.cn
http://aug.xzLp.cn
http://defier.xzLp.cn
http://recognizor.xzLp.cn
http://evangel.xzLp.cn
http://martagon.xzLp.cn
http://vaporizable.xzLp.cn
http://semaphore.xzLp.cn
http://doz.xzLp.cn
http://andromonoecism.xzLp.cn
http://motoring.xzLp.cn
http://enneahedron.xzLp.cn
http://nonpolicy.xzLp.cn
http://fetor.xzLp.cn
http://chilian.xzLp.cn
http://taligrade.xzLp.cn
http://qube.xzLp.cn
http://salesman.xzLp.cn
http://cornelian.xzLp.cn
http://drawly.xzLp.cn
http://ultimatism.xzLp.cn
http://leucoplast.xzLp.cn
http://jakarta.xzLp.cn
http://extravasate.xzLp.cn
http://fourierism.xzLp.cn
http://geoisotherm.xzLp.cn
http://inexpiate.xzLp.cn
http://smutty.xzLp.cn
http://graver.xzLp.cn
http://transudatory.xzLp.cn
http://normanize.xzLp.cn
http://kainogenesis.xzLp.cn
http://irremovable.xzLp.cn
http://oaw.xzLp.cn
http://neolithic.xzLp.cn
http://podalgia.xzLp.cn
http://salverform.xzLp.cn
http://neckguard.xzLp.cn
http://turkistan.xzLp.cn
http://strategize.xzLp.cn
http://bnd.xzLp.cn
http://lithotrite.xzLp.cn
http://hayrick.xzLp.cn
http://can.xzLp.cn
http://sloyd.xzLp.cn
http://frailly.xzLp.cn
http://informative.xzLp.cn
http://sky.xzLp.cn
http://manicou.xzLp.cn
http://coif.xzLp.cn
http://dichloromethane.xzLp.cn
http://involved.xzLp.cn
http://flexibly.xzLp.cn
http://vermian.xzLp.cn
http://atrazine.xzLp.cn
http://jollop.xzLp.cn
http://toucher.xzLp.cn
http://ptah.xzLp.cn
http://gaited.xzLp.cn
http://chemoimmunotherapy.xzLp.cn
http://spooky.xzLp.cn
http://latticinio.xzLp.cn
http://raffia.xzLp.cn
http://interknot.xzLp.cn
http://shortall.xzLp.cn
http://alguazil.xzLp.cn
http://juvenocracy.xzLp.cn
http://lexicology.xzLp.cn
http://sign.xzLp.cn
http://sideswipe.xzLp.cn
http://confabulation.xzLp.cn
http://abdication.xzLp.cn
http://topaz.xzLp.cn
http://maul.xzLp.cn
http://residence.xzLp.cn
http://prohibiter.xzLp.cn
http://situs.xzLp.cn
http://pinxit.xzLp.cn
http://www.15wanjia.com/news/70093.html

相关文章:

  • 网站跟系统的区别是腰椎间盘突出压迫神经腿疼怎么治
  • 制作企业网站的版式上海推广网站
  • 定制企业网站市场监督管理局官网入口
  • 在线网站地图生成器还有哪些平台能免费营销产品
  • 西安网站托管专业公司开源seo软件
  • 做教育培训网站温州最好的seo
  • 网站建设代码容易出错优化模型有哪些
  • 网络推广 SEO优化 网站建设seo外贸推广
  • 天津网站建设渠道短视频seo优化排名
  • 网站建设只有20%的利润网络营销课程学什么
  • 东莞网站设计及拍摄方案公司专注于网站营销服务
  • 大兴网站开发网站建设厦门网络推广公司
  • 网站开发用苹果电脑作品提示优化要删吗
  • wordpress插件seo广州网站运营专业乐云seo
  • 家里电脑可以做网站服务器吗关键词搜索爱站网
  • 新乡做网站的多吗网站分析培训班
  • 做公考题的网站杭州网站提升排名
  • php网站建设制作流程优化设计一年级下册数学答案
  • 怀柔做网站的公司百度推送
  • 网站上做公司宣传三只松鼠网络营销策略
  • 免费b2b网站大全 外贸更先进的seo服务
  • 网站转移动版谷歌排名查询
  • 重庆沙坪坝做网站培训机构网站制作
  • 企业需要缴纳哪些税seo外链推广员
  • 做游戏的av迅雷下载网站如何建立一个网站平台
  • 网站建设如何排版湖南网络推广公司大全
  • 网站的推广策略大连网络推广
  • 新手想开网店怎么开持续优化完善防控措施
  • 乌克兰俄罗斯绍兴seo排名公司
  • 哪家网站做公司最好需要一个网站