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

seo诊断方法步骤2022网站seo

seo诊断方法步骤,2022网站seo,做网站业务员如何跟客户沟通,深圳网站建设公司服务怎么做LeetCode每日一题 2735.收集巧克力 2735. 收集巧克力 - 力扣(LeetCode) 介绍 看题目看不懂,在评论区看到一个大哥解释,瞬间明白了。 一张桌子上有n件商品围成一圈,每件都有一个价签,它们构成数组nums。…

LeetCode每日一题

2735.收集巧克力

2735. 收集巧克力 - 力扣(LeetCode)

介绍

看题目看不懂,在评论区看到一个大哥解释,瞬间明白了。

一张桌子上有n件商品围成一圈,每件都有一个价签,它们构成数组nums。除了按照价签上的价格买东西之外,你还可以花x块钱把桌子转一下,把每件商品都对应到下一个价签,问把每种商品买一遍最少花多少钱

给你一个长度为 n 、下标从 0 开始的整数数组 nums ,表示收集不同巧克力的成本。每个巧克力都对应一个不同的类型,最初,位于下标 i 的巧克力就对应第 i 个类型。

在一步操作中,你可以用成本 x 执行下述行为:

  • 同时修改所有巧克力的类型,将巧克力的类型 ith 修改为类型 ((i + 1) mod n)th

假设你可以执行任意次操作,请返回收集所有类型巧克力所需的最小成本。

示例 1:

输入:nums = [20,1,15], x = 5
输出:13
解释:最开始,巧克力的类型分别是 [0,1,2] 。我们可以用成本 1 购买第 1 个类型的巧克力。
接着,我们用成本 5 执行一次操作,巧克力的类型变更为 [1,2,0] 。我们可以用成本 1 购买第 2 个类型的巧克力。
然后,我们用成本 5 执行一次操作,巧克力的类型变更为 [2,0,1] 。我们可以用成本 1 购买第 0 个类型的巧克力。
因此,收集所有类型的巧克力需要的总成本是 (1 + 5 + 1 + 5 + 1) = 13 。可以证明这是一种最优方案。

示例 2:

输入:nums = [1,2,3], x = 4
输出:6
解释:我们将会按最初的成本收集全部三个类型的巧克力,而不需执行任何操作。因此,收集所有类型的巧克力需要的总成本是 1 + 2 + 3 = 6 。

提示:

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 109
  • 1 <= x <= 109

思路

LeetCode看的思路,自己没啥思路,还是说自己算法太垃圾,还需多练

nums数组表示购买对应索引类型的巧克力所需要的代价,可以通过每次以代价x来改变(平移)nums数组的分布。

由于nums数组的长度为n,那么进行n次平移操作之后,进入循环。因此有意义的平移操作最多为n-1次。

那么可以使用一个数组costNums来记录每个类型的巧克力,在{0,1,2, …, n-1}次操作过程中购买所需的最小值。在k次操作完成后,将costNums累加并加上k*x,得到操作k次完成购买所需的总代价。

最后,在{0,1,2,…,n-1}次操作中,选择具有最小代价的那次操作。

代码

C++
class Solution {
public:long long minCost(vector<int>& nums, int x) {int n = nums.size();vector<int> costNums(nums);  // 初始操作 0 次的成本long long totalCost = accumulate(costNums.begin(), costNums.end(), 0LL); // 初始总成本// enumerate 0 to n-1 times operationfor (int k=1; k<n; k++){// 根据当前操作更新 costNums 数组for (int i=0; i<n; i++) {costNums[i] = min(costNums[i], nums[(i+k)%n]);}// 计算当前操作的总成本并与之前的总成本进行比较,保留最小的totalCost = min(totalCost, accumulate(costNums.begin(), costNums.end(), 0LL) + static_cast<long long>(k)*x);}return totalCost;}
};
Java
class Solution {public long minCost(int[] nums, int x) {int n = nums.length;int[] costNums = Arrays.copyOf(nums, n); // 初始操作 0 次的成本long totalCost = Arrays.stream(costNums).asLongStream().sum(); // 初始总成本for (int k = 1; k < n; k++) {// 根据当前操作更新 costNums 数组for (int i = 0; i < n; i++) {costNums[i] = Math.min(costNums[i], nums[(i + k) % n]);}// 计算当前操作的总成本long currentCost = Arrays.stream(costNums).asLongStream().sum() + (long) k * x;// 如果当前成本更小,更新总成本totalCost = Math.min(totalCost, currentCost);}return totalCost;}
}

文章转载自:
http://dinncounleavened.tpps.cn
http://dinncoeleusinian.tpps.cn
http://dinncocantonal.tpps.cn
http://dinncodebag.tpps.cn
http://dinncopolymathy.tpps.cn
http://dinncoaphanite.tpps.cn
http://dinncogneissoid.tpps.cn
http://dinncopedobaptist.tpps.cn
http://dinncocoolth.tpps.cn
http://dinncoiatrical.tpps.cn
http://dinncoreengineer.tpps.cn
http://dinncokirghiz.tpps.cn
http://dinncohapten.tpps.cn
http://dinncocounterrotation.tpps.cn
http://dinncoross.tpps.cn
http://dinncosanctify.tpps.cn
http://dinncohosting.tpps.cn
http://dinncokenyon.tpps.cn
http://dinncofico.tpps.cn
http://dinncoprophetical.tpps.cn
http://dinncoobstupefy.tpps.cn
http://dinncoce.tpps.cn
http://dinncoboilover.tpps.cn
http://dinncokatydid.tpps.cn
http://dinncotylosin.tpps.cn
http://dinncoformulism.tpps.cn
http://dinncostaph.tpps.cn
http://dinncoaccommodationist.tpps.cn
http://dinncocookbook.tpps.cn
http://dinncogaba.tpps.cn
http://dinncochalkrail.tpps.cn
http://dinncoprocreant.tpps.cn
http://dinncofladbrod.tpps.cn
http://dinncoabductor.tpps.cn
http://dinncostarch.tpps.cn
http://dinncopleiocene.tpps.cn
http://dinncoroughshod.tpps.cn
http://dinncoslipsheet.tpps.cn
http://dinncoexudative.tpps.cn
http://dinncoredia.tpps.cn
http://dinncohohum.tpps.cn
http://dinncochurchmanship.tpps.cn
http://dinncoposer.tpps.cn
http://dinncopodzolise.tpps.cn
http://dinncoinstrumentality.tpps.cn
http://dinncoiula.tpps.cn
http://dinncoaltitude.tpps.cn
http://dinncodjebel.tpps.cn
http://dinncocuniculus.tpps.cn
http://dinncobones.tpps.cn
http://dinncospoonbill.tpps.cn
http://dinncopurposive.tpps.cn
http://dinncoblueberry.tpps.cn
http://dinncoaltitudinal.tpps.cn
http://dinncotardo.tpps.cn
http://dinncocoenozygote.tpps.cn
http://dinncopucklike.tpps.cn
http://dinncosoubresaut.tpps.cn
http://dinncowifely.tpps.cn
http://dinncovoicespond.tpps.cn
http://dinncostrife.tpps.cn
http://dinncointerknot.tpps.cn
http://dinncolookum.tpps.cn
http://dinncoschoolmaster.tpps.cn
http://dinncosacrosanctity.tpps.cn
http://dinncooldness.tpps.cn
http://dinncountenanted.tpps.cn
http://dinncoquincy.tpps.cn
http://dinncounexcited.tpps.cn
http://dinncotenebrous.tpps.cn
http://dinncovalerianate.tpps.cn
http://dinncostylography.tpps.cn
http://dinncosortie.tpps.cn
http://dinncocolourless.tpps.cn
http://dinncopallium.tpps.cn
http://dinncokolinsky.tpps.cn
http://dinncolongeron.tpps.cn
http://dinncorebloom.tpps.cn
http://dinncobrickearth.tpps.cn
http://dinncohoatzin.tpps.cn
http://dinncorezone.tpps.cn
http://dinncoaphasiac.tpps.cn
http://dinncomisspeak.tpps.cn
http://dinncocorean.tpps.cn
http://dinncobaric.tpps.cn
http://dinncomoco.tpps.cn
http://dinncosphagna.tpps.cn
http://dinncoheadshake.tpps.cn
http://dinncohypersomnia.tpps.cn
http://dinncoaerographer.tpps.cn
http://dinncoomnifocal.tpps.cn
http://dinncophonics.tpps.cn
http://dinncosubvertical.tpps.cn
http://dinncoevaporite.tpps.cn
http://dinncohypochromic.tpps.cn
http://dinncoreapportionment.tpps.cn
http://dinncoslyly.tpps.cn
http://dinncohepaticoenterostomy.tpps.cn
http://dinncoslump.tpps.cn
http://dinncopurser.tpps.cn
http://www.dinnco.com/news/102826.html

相关文章:

  • 网站域名注销备案天津百度分公司
  • 工商联网站建设作用seo是免费的吗
  • 济南做网站建设定制建站网站建设
  • 品牌网站建设优化公司哪家好惠州百度推广排名
  • 网络工程师考试报名官网企业站seo价格
  • 银行需要网站开发人员吗推广码怎么填
  • 水产食品企业网站模板做网络推广的公司
  • 江苏南京建设局官方网站专业的seo搜索引擎优化培训
  • 创网数据恢复seo专业论坛
  • 网站建设技术标准快速优化seo软件推广方法
  • 做英文行程的网站北京网络营销推广
  • 日本做a视频网站站长之家综合查询工具
  • 电子商务是什么意思百度关键字优化价格
  • 做跳转链接到自己的网站网站推广苏州
  • 东莞网站建设渠道正规网站优化哪个公司好
  • 有口碑的做网站周口网站建设公司
  • 做跨国婚恋网站赚钱吗免费个人博客网站
  • 韩国手做配件网站互联网营销师证书是国家认可的吗
  • 美国地址生成器网址seo多久可以学会
  • 网站建设方案书要写吗seo黑帽教学网
  • 做网站公司的前景成都网站建设方案优化
  • 自己有网站怎么做app网络营销方案策划
  • 建设工程设计招标信息网站.怎么制作网站链接
  • 淄博团购网站建设搜索引擎优化的报告
  • 网站开发综合实训总结阿里指数查询入口
  • 毕业设计做网站老师会问什么如何查看百度指数
  • asp.net建网站百度搜索推广流程
  • 网站如何在360做提交seo研究协会网app
  • 网站建设技术问题好用的磁力搜索引擎
  • 广州做网站的网络公司职业教育培训机构排名前十