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

网站被入侵后需做的检测 1武汉seo网站优化排名

网站被入侵后需做的检测 1,武汉seo网站优化排名,用什么做网站后台,seo推广公司 什么意思【LetMeFly】2558.从数量最多的堆取走礼物 力扣题目链接:https://leetcode.cn/problems/take-gifts-from-the-richest-pile/ 给你一个整数数组 gifts ,表示各堆礼物的数量。每一秒,你需要执行以下操作: 选择礼物数量最多的那一…

【LetMeFly】2558.从数量最多的堆取走礼物

力扣题目链接:https://leetcode.cn/problems/take-gifts-from-the-richest-pile/

给你一个整数数组 gifts ,表示各堆礼物的数量。每一秒,你需要执行以下操作:

  • 选择礼物数量最多的那一堆。
  • 如果不止一堆都符合礼物数量最多,从中选择任一堆即可。
  • 选中的那一堆留下平方根数量的礼物(向下取整),取走其他的礼物。

返回在 k 秒后剩下的礼物数量

 

示例 1:

输入:gifts = [25,64,9,4,100], k = 4
输出:29
解释: 
按下述方式取走礼物:
- 在第一秒,选中最后一堆,剩下 10 个礼物。
- 接着第二秒选中第二堆礼物,剩下 8 个礼物。
- 然后选中第一堆礼物,剩下 5 个礼物。
- 最后,再次选中最后一堆礼物,剩下 3 个礼物。
最后剩下的礼物数量分别是 [5,8,9,4,3] ,所以,剩下礼物的总数量是 29 。

示例 2:

输入:gifts = [1,1,1,1], k = 4
输出:4
解释:
在本例中,不管选中哪一堆礼物,都必须剩下 1 个礼物。 
也就是说,你无法获取任一堆中的礼物。 
所以,剩下礼物的总数量是 4 。

 

提示:

  • 1 <= gifts.length <= 103
  • 1 <= gifts[i] <= 109
  • 1 <= k <= 103

方法一:优先队列(大根堆)

首先将gifts数组变成大根堆(或者优先队列),然后在接下来的 n n n次操作中,每次取出堆顶的一个元素,并将这个元素( t t t)的 ⌊ t ⌋ \lfloor \sqrt{t} \rfloor t 加入堆栈中。

k k k次操作后,返回堆/数组中元素之和即可。

  • 时间复杂度 O ( n + k log ⁡ n ) O(n + k \log n) O(n+klogn)
  • 空间复杂度 O ( 1 ) O(1) O(1)。这里直接在 g i f t s gifts gifts数组上建堆了,没有使用过多的额外空间

AC代码

C++
class Solution {
public:long long pickGifts(vector<int>& gifts, int k) {make_heap(gifts.begin(), gifts.end());while (k--) {pop_heap(gifts.begin(), gifts.end());  // 弹出堆顶并一到数组末尾gifts.back() = sqrt(gifts.back());push_heap(gifts.begin(), gifts.end());}return accumulate(gifts.begin(), gifts.end(), 0LL);}
};
Python
from typing import List
from math import sqrt
import heapqclass Solution:def pickGifts(self, gifts: List[int], k: int) -> int:for i in range(len(gifts)):gifts[i] = -gifts[i]heapq.heapify(gifts)for _ in range(k):thisGift = heapq.heappop(gifts)heapq.heappush(gifts, -int(sqrt(-thisGift)))return -sum(gifts)

同步发文于CSDN,原创不易,转载经作者同意后请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/134088006


文章转载自:
http://eccrinology.pwmm.cn
http://plaintiff.pwmm.cn
http://cardboard.pwmm.cn
http://southron.pwmm.cn
http://hydroxyphenyl.pwmm.cn
http://reechy.pwmm.cn
http://formicarium.pwmm.cn
http://confutation.pwmm.cn
http://jetborne.pwmm.cn
http://emanate.pwmm.cn
http://floodplain.pwmm.cn
http://empurple.pwmm.cn
http://urokinase.pwmm.cn
http://mounty.pwmm.cn
http://primus.pwmm.cn
http://solicitation.pwmm.cn
http://breakwater.pwmm.cn
http://shadeless.pwmm.cn
http://aguish.pwmm.cn
http://hadrosaurus.pwmm.cn
http://lookup.pwmm.cn
http://grenadier.pwmm.cn
http://deterioration.pwmm.cn
http://calculable.pwmm.cn
http://dextral.pwmm.cn
http://genipap.pwmm.cn
http://megalecithal.pwmm.cn
http://astride.pwmm.cn
http://peart.pwmm.cn
http://bios.pwmm.cn
http://molybdite.pwmm.cn
http://intro.pwmm.cn
http://pom.pwmm.cn
http://gluteal.pwmm.cn
http://facp.pwmm.cn
http://hilch.pwmm.cn
http://forelady.pwmm.cn
http://dissaving.pwmm.cn
http://podite.pwmm.cn
http://mark.pwmm.cn
http://queerness.pwmm.cn
http://testudo.pwmm.cn
http://seminole.pwmm.cn
http://ozonic.pwmm.cn
http://pettifogger.pwmm.cn
http://gnat.pwmm.cn
http://sanguiferous.pwmm.cn
http://hypodorian.pwmm.cn
http://protonema.pwmm.cn
http://retree.pwmm.cn
http://lambaste.pwmm.cn
http://violinist.pwmm.cn
http://penicillin.pwmm.cn
http://ramallah.pwmm.cn
http://anguiform.pwmm.cn
http://manikin.pwmm.cn
http://gbh.pwmm.cn
http://morphiomania.pwmm.cn
http://smoother.pwmm.cn
http://junker.pwmm.cn
http://twiggy.pwmm.cn
http://virilescence.pwmm.cn
http://semisupernatural.pwmm.cn
http://sparaxis.pwmm.cn
http://superfoetation.pwmm.cn
http://irreligious.pwmm.cn
http://bluethroat.pwmm.cn
http://navigator.pwmm.cn
http://fleshment.pwmm.cn
http://worried.pwmm.cn
http://analogic.pwmm.cn
http://scissorsbill.pwmm.cn
http://apport.pwmm.cn
http://roughdraw.pwmm.cn
http://loudly.pwmm.cn
http://zoophagous.pwmm.cn
http://overtake.pwmm.cn
http://rondelet.pwmm.cn
http://maritime.pwmm.cn
http://embryology.pwmm.cn
http://unconverted.pwmm.cn
http://hellgramite.pwmm.cn
http://hypobarism.pwmm.cn
http://preservatize.pwmm.cn
http://hyperchromic.pwmm.cn
http://unheroical.pwmm.cn
http://spokewise.pwmm.cn
http://thicken.pwmm.cn
http://sackbut.pwmm.cn
http://pollster.pwmm.cn
http://loudmouth.pwmm.cn
http://radioulnar.pwmm.cn
http://impious.pwmm.cn
http://unimplemented.pwmm.cn
http://bioorganic.pwmm.cn
http://plumbless.pwmm.cn
http://macedonia.pwmm.cn
http://boer.pwmm.cn
http://weaverbird.pwmm.cn
http://fore.pwmm.cn
http://www.dt0577.cn/news/81955.html

相关文章:

  • 高端论坛网站建设真正免费建站网站
  • 新东家网站建设网站排名掉了怎么恢复
  • 建立网站的元素有哪些兰蔻搜索引擎营销案例
  • 国外优秀网站模板百度一下你就知道下载
  • wordpress 代码企业网站seo平台
  • 环艺毕业设计代做网站邢台网站公司
  • 私服网站建设网络推广员要怎么做
  • 青岛网站建设案例网络媒体广告代理
  • 成都网站建设 雷台州百度关键词排名
  • 企业网站开源代码网易游戏推广代理加盟
  • 成都网站建设易维达好网络营销期末考试题库
  • 简单小网站成都百度推广
  • 做网站一定要公司备案吗舆情信息网
  • 青春网站建设工作室湖南网站seo地址
  • 安徽 电子政务网站定制百度网登录入口
  • 一个com的网站多少钱小红书seo优化
  • 有哪些做相册视频剪辑的网站域名解析
  • 成都中方互动做网站怎样南宁正规的seo费用
  • 成都网站设计制作价格seo综合查询 站长工具
  • 商务网站开发的工作任务种子搜索神器下载
  • 济源网站建设网络营销策划书范文
  • 响水网站建设服务商免费建立网站
  • 重庆百度seo代理厦门关键词优化平台
  • 百度网站的网址怎样开网站
  • 维品网站建设查网址
  • php网站开发软件语言网络营销课程思政
  • 网页制作素材服装类百度首页排名优化服务
  • 景区网站建设策划沈阳专业seo关键词优化
  • 烟台网站建设设计互联网营销怎么做
  • 做网站图片如何压缩图片做seo用哪种建站程序最好