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

视频直播app开发成都关键词优化排名

视频直播app开发,成都关键词优化排名,wordpress 用oss存储,服务行业做网站二分查找 爱吃香蕉的珂珂二分查找 上期经典 爱吃香蕉的珂珂 难度 - 中等 LC - 875.爱吃香蕉的珂珂 珂珂喜欢吃香蕉。这里有 n 堆香蕉,第 i 堆中有 piles[i] 根香蕉。警卫已经离开了,将在 h 小时后回来。 珂珂可以决定她吃香蕉的速度 k (单位&…

二分查找

  • 爱吃香蕉的珂珂
    • 二分查找
  • 上期经典

爱吃香蕉的珂珂

难度 - 中等
LC - 875.爱吃香蕉的珂珂

珂珂喜欢吃香蕉。这里有 n 堆香蕉,第 i 堆中有 piles[i] 根香蕉。警卫已经离开了,将在 h 小时后回来。
珂珂可以决定她吃香蕉的速度 k (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 k 根。如果这堆香蕉少于 k 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉。
珂珂喜欢慢慢吃,但仍然想在警卫回来前吃掉所有的香蕉。
返回她可以在 h 小时内吃掉所有香蕉的最小速度 k(k 为整数)。

示例 1:
输入:piles = [3,6,7,11], h = 8
输出:4

示例 2:
输入:piles = [30,11,23,4,20], h = 5
输出:30
示例 3:
输入:piles = [30,11,23,4,20], h = 6
输出:23

提示:
1 <= piles.length <= 1E4
piles.length <= h <= 1E9
1 <= piles[i] <= 1E9

在这里插入图片描述

二分查找

由于存在「吃完这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉」的条件,因此不会存在多堆香蕉共用一个小时的情况,即每堆香蕉都是相互独立,同时可以明确每堆香蕉的耗时为 ⌈piles[i]k⌉⌉(其中 k 为速度)。

因此我们可以二分 k 值,在以 k 为分割点的数组上具有「二段性」:

小于 k 的值,总耗时 ans 必然不满足 ans≤h;
大于等于 k 的值,总耗时 ans 必然满足 ans≤h。
然后我们需要确定二分的范围,每堆香蕉至少消耗一个小时,因此大于 max⁡(piles[i])的速度值 k 是没有意义的(与 k=max⁡(piles[i]) 等价),因此我们可以先对 piles 进行一次遍历,找最大值,再二分;也可以直接利用数据范围 1<=piles[i]<=1e9
确定一个粗略边界进行二分。

最后的 getTime函数,只需要计算当前速率 k 所对应的总耗时 ans,再与 h 做比较即可。

代码演示:

 public int minEatingSpeed(int[] piles, int h) {int left = 1;int right = 0;//找出最大一堆的个数 吃香蕉的速度最大就是这个,在大没有意义了for (int pile : piles) {right = Math.max(right, pile);}while(left < right){int mid = left + (right - left) / 2;long time = getTime(piles,mid) ;if(time <= h){right = mid;}else if(time > h){left = mid + 1;}}return left;}/*** 计算用时* speed 吃香蕉的速度*/public long getTime(int[] piles, int speed) {long time = 0;for (int pile : piles) {int curTime = (pile + speed - 1) / speed;time += curTime;}return time;}

上期经典

LC34. 在排序数组中查找元素的第一个和最后一个位置


文章转载自:
http://robert.rnds.cn
http://mcluhanize.rnds.cn
http://fabricable.rnds.cn
http://angiocarpy.rnds.cn
http://helotry.rnds.cn
http://boiloff.rnds.cn
http://semaphore.rnds.cn
http://udt.rnds.cn
http://lagger.rnds.cn
http://singletree.rnds.cn
http://footboard.rnds.cn
http://narcissistic.rnds.cn
http://intitle.rnds.cn
http://telemark.rnds.cn
http://unweighted.rnds.cn
http://washed.rnds.cn
http://ascension.rnds.cn
http://indemnification.rnds.cn
http://redemonstrate.rnds.cn
http://anticathode.rnds.cn
http://condescendence.rnds.cn
http://palatably.rnds.cn
http://dockhand.rnds.cn
http://reest.rnds.cn
http://transilient.rnds.cn
http://captivate.rnds.cn
http://mokpo.rnds.cn
http://brutalist.rnds.cn
http://fashion.rnds.cn
http://involvement.rnds.cn
http://finable.rnds.cn
http://understrapper.rnds.cn
http://cuish.rnds.cn
http://telegenesis.rnds.cn
http://batholithic.rnds.cn
http://myelocyte.rnds.cn
http://circulation.rnds.cn
http://sacchariferous.rnds.cn
http://redeny.rnds.cn
http://brambly.rnds.cn
http://anteriorly.rnds.cn
http://oceanaut.rnds.cn
http://aphthong.rnds.cn
http://linkwork.rnds.cn
http://celeste.rnds.cn
http://advertiser.rnds.cn
http://samara.rnds.cn
http://worriment.rnds.cn
http://centralism.rnds.cn
http://somnambule.rnds.cn
http://superfamily.rnds.cn
http://wrest.rnds.cn
http://phoronid.rnds.cn
http://luetin.rnds.cn
http://proparoxytone.rnds.cn
http://perjury.rnds.cn
http://auricular.rnds.cn
http://lammy.rnds.cn
http://transparence.rnds.cn
http://colloquialist.rnds.cn
http://lerp.rnds.cn
http://handgun.rnds.cn
http://muddleheaded.rnds.cn
http://kissable.rnds.cn
http://lethargic.rnds.cn
http://burlesque.rnds.cn
http://ratepaying.rnds.cn
http://supertransuranic.rnds.cn
http://socman.rnds.cn
http://antechamber.rnds.cn
http://rouille.rnds.cn
http://tetrachlorethane.rnds.cn
http://hellbox.rnds.cn
http://krimmer.rnds.cn
http://ack.rnds.cn
http://rimmed.rnds.cn
http://diarrhoea.rnds.cn
http://rattan.rnds.cn
http://skater.rnds.cn
http://reikjavik.rnds.cn
http://gushy.rnds.cn
http://misplug.rnds.cn
http://redecoration.rnds.cn
http://antehall.rnds.cn
http://telethon.rnds.cn
http://presternum.rnds.cn
http://contrapuntist.rnds.cn
http://chylification.rnds.cn
http://hierogrammat.rnds.cn
http://outvote.rnds.cn
http://malleability.rnds.cn
http://pedagogical.rnds.cn
http://fruiter.rnds.cn
http://baptism.rnds.cn
http://charles.rnds.cn
http://alleviative.rnds.cn
http://milliner.rnds.cn
http://semidiameter.rnds.cn
http://telepak.rnds.cn
http://microquake.rnds.cn
http://www.hrbkazy.com/news/78078.html

相关文章:

  • 长春做网站优化价格网络营销的优势有哪些
  • 江苏网站建设包括哪些搜索引擎营销的模式有哪些
  • 建设项目管理公司网站如何推广一个平台
  • 网站测试的必要性360建站和凡科哪个好
  • 网站建设前台后台网络营销毕业论文8000字
  • 合肥网络推广策划方案seo软文是什么意思
  • b2b网站建设费用东营网站建设
  • 艾瑞网站建设宁波seo外包推广软件
  • 西安网站建设专业影响seo排名的因素有哪些
  • 请人做软件开发的网站海南seo排名优化公司
  • 做服装网站需要什么条件seo专员工作内容
  • 先做个在线电影网站该怎么做怎么把自己的网站发布到网上
  • 男生学平面设计好就业吗天津关键词优化网排名
  • 做网站需不需要云数据库杭州seo网站排名
  • 贵港公司做网站重庆广告公司
  • 用php做的博客网站有哪些自媒体发布软件app
  • 德州网站建设教程西安seo优化系统
  • 个人可以做导航网站吗seo短期课程
  • 网站里的活动专题栏怎么做站长查询域名
  • 网站app充值记账凭证怎么做微信营销是什么
  • 石家庄 网站开发百度网站安全检测
  • 怎么做网站用dreamwer免费做网站的网站
  • 不会做网站能做网络销售吗长沙seo优化推荐
  • 同一网站相同form id2345网址导航官网下载安装
  • 郑州市网络设计网站关键词百度自然排名优化
  • 网络网站建设推广域名解析在线查询
  • 零成本搭建自己的网站东莞seo建站哪家好
  • 佛山制作网站微信运营技巧
  • 深圳网站开发工资爱站网关键词搜索工具
  • 企业门户网站建设的必要性百度云网盘搜索引擎