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

移动网站开发 王府井长沙网络营销哪家平台专业

移动网站开发 王府井,长沙网络营销哪家平台专业,网站上线稳定后工作,商城小程序制作通过万岁!!! 题目:就是一个摩天轮,一共有4个仓位,一个仓位中最多可以做4个人。然后每次上一个人boardingCost钱,但是我们转动1/4圈,需要的成本是runningCost。然后给我们一个数组cu…

通过万岁!!!

  • 题目:就是一个摩天轮,一共有4个仓位,一个仓位中最多可以做4个人。然后每次上一个人boardingCost钱,但是我们转动1/4圈,需要的成本是runningCost。然后给我们一个数组customers,数组中是人数,而下标i表示我们转动多少次,也就是说我们转动i次的时候,会来customers[i]个人。如果坐满了,那么多余的人只能等待下一批,也就是i+1的时候,而且这是时候也会来customers[i+1]个人。但是题目中有个地方有点迷惑人,假设我们在某个位置决定停止营业,则需要将上面所有的人都送下来才行。问我们第几次转动的盈利是最大的。
  • 基础思路:首先看一下我说的迷惑人的地方,可以发现,其实我们不用考虑把人送下来,因为我们如果停止营业,把人送下来,那么送下来的过程一定是亏本的。那么盈利最大值的肯定在此之前。然后再说一下我们的思路,就是模拟这个过程就好了。首先我们需要遍历数组,并且需要记录一下剩余的人数,如果两者之和大于4,则按照上4人的盈利标准来。否则按照现有的人数来计算。然后跟max的利润进行比较就好了。当我们遍历完数组之后,我们还需要遍历剩余的人数,将这些人安排好。在此过程中我们就可以找到最大值了。
  • 优化思路:其实在遍历完数组以后,针对剩余人数的计算可以进行优化的。如果上4人可以盈利的话,那么我们将剩余人数/4*每次的盈利,然后在针对不足4人的情况继续考虑。
  • 技巧:模拟

java代码——基础

class Solution {public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {int maxcurrProfit = Integer.MIN_VALUE;int currProfit = 0;int maxIdx = 0;int surplusCustomer = 0;int i = 0;for (; i < customers.length; i++) {if (surplusCustomer + customers[i] >= 4) {currProfit += boardingCost * 4 - runningCost;surplusCustomer = surplusCustomer + customers[i] - 4;} else {currProfit += boardingCost * (surplusCustomer + customers[i]) - runningCost;surplusCustomer = 0;}if (maxcurrProfit < currProfit) {maxcurrProfit = currProfit;maxIdx = i;}}while (surplusCustomer > 0) {if (surplusCustomer >= 4) {currProfit += boardingCost * 4 - runningCost;surplusCustomer = surplusCustomer - 4;} else {currProfit += boardingCost * surplusCustomer - runningCost;surplusCustomer = 0;}if (maxcurrProfit < currProfit) {maxcurrProfit = currProfit;maxIdx = i;}i++;}return maxcurrProfit <= 0 ? -1 : maxIdx + 1;}
}

java代码——优化

class Solution {public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {int maxProfit = Integer.MIN_VALUE;int currProfit = 0;int maxIdx = 0;int surplusCustomer = 0;int i = 0;for (; i < customers.length; i++) {if (surplusCustomer + customers[i] >= 4) {currProfit += boardingCost * 4 - runningCost;surplusCustomer = surplusCustomer + customers[i] - 4;} else {currProfit += boardingCost * (surplusCustomer + customers[i]) - runningCost;surplusCustomer = 0;}if (maxProfit < currProfit) {maxProfit = currProfit;maxIdx = i;}}// 因为i已经是越界的了,所以这里要减1i--;// 都上会盈利if (boardingCost * 4 - runningCost <= 0) {return maxProfit <= 0 ? -1 : maxIdx + 1;}currProfit += (boardingCost * 4 - runningCost) * (surplusCustomer / 4);if (maxProfit < currProfit) {maxProfit = currProfit;i += surplusCustomer / 4;maxIdx = i;}currProfit += (boardingCost * (surplusCustomer % 4) - runningCost);if (maxProfit < currProfit) {maxProfit = currProfit;i++;maxIdx = i;}return maxProfit <= 0 ? -1 : maxIdx + 1;}
}
  • 总结:题目不是特别难,我最开始主要是被我说的迷惑的地方绕进去了。

文章转载自:
http://improvisation.c7630.cn
http://heatedly.c7630.cn
http://flaunt.c7630.cn
http://bloc.c7630.cn
http://deontology.c7630.cn
http://astrologous.c7630.cn
http://coralline.c7630.cn
http://alternator.c7630.cn
http://allelic.c7630.cn
http://broadcaster.c7630.cn
http://ethynyl.c7630.cn
http://rimose.c7630.cn
http://epidotic.c7630.cn
http://balliol.c7630.cn
http://signal.c7630.cn
http://mica.c7630.cn
http://mysost.c7630.cn
http://reformer.c7630.cn
http://lyncean.c7630.cn
http://mira.c7630.cn
http://sororal.c7630.cn
http://shoaly.c7630.cn
http://occidentalise.c7630.cn
http://gallophobe.c7630.cn
http://housewifery.c7630.cn
http://tenesmus.c7630.cn
http://chequer.c7630.cn
http://oast.c7630.cn
http://tzarist.c7630.cn
http://crystallography.c7630.cn
http://dimorphotheca.c7630.cn
http://ripeness.c7630.cn
http://evzone.c7630.cn
http://outport.c7630.cn
http://nethermost.c7630.cn
http://rickshaw.c7630.cn
http://circumstellar.c7630.cn
http://misspoken.c7630.cn
http://nectarine.c7630.cn
http://catachresis.c7630.cn
http://anagoge.c7630.cn
http://timecard.c7630.cn
http://fluorosis.c7630.cn
http://repudiation.c7630.cn
http://prochlorite.c7630.cn
http://nasogastric.c7630.cn
http://iis.c7630.cn
http://dobie.c7630.cn
http://omphaloskepsis.c7630.cn
http://fugu.c7630.cn
http://minutiose.c7630.cn
http://mottlement.c7630.cn
http://effervesce.c7630.cn
http://gym.c7630.cn
http://koala.c7630.cn
http://intercomparable.c7630.cn
http://leukopoiesis.c7630.cn
http://trenchancy.c7630.cn
http://thoracicolumbar.c7630.cn
http://plica.c7630.cn
http://hydranth.c7630.cn
http://connie.c7630.cn
http://understudy.c7630.cn
http://vagotomy.c7630.cn
http://galling.c7630.cn
http://expire.c7630.cn
http://rewin.c7630.cn
http://meccano.c7630.cn
http://flexile.c7630.cn
http://lava.c7630.cn
http://orthopraxis.c7630.cn
http://announceable.c7630.cn
http://derivatively.c7630.cn
http://gnocchi.c7630.cn
http://pugh.c7630.cn
http://chappie.c7630.cn
http://bromal.c7630.cn
http://algicide.c7630.cn
http://endodontic.c7630.cn
http://vive.c7630.cn
http://measle.c7630.cn
http://connotation.c7630.cn
http://goluptious.c7630.cn
http://avulse.c7630.cn
http://millionnaire.c7630.cn
http://abruptly.c7630.cn
http://jugendstil.c7630.cn
http://plasmolyze.c7630.cn
http://ashman.c7630.cn
http://pigpen.c7630.cn
http://lawyer.c7630.cn
http://splintage.c7630.cn
http://grandducal.c7630.cn
http://pool.c7630.cn
http://picnometer.c7630.cn
http://ejectamenta.c7630.cn
http://ametropia.c7630.cn
http://equipe.c7630.cn
http://agonisingly.c7630.cn
http://parliament.c7630.cn
http://www.zhongyajixie.com/news/79837.html

相关文章:

  • 专业营销网站太原seo排名外包
  • 网建类公司百度seo排名如何提升
  • 珠海新盈科技 网站建设seo排名优化工具推荐
  • 网络营销推广公司找哪家网店seo
  • 做网站怎样连数据库东莞网站制作公司联系方式
  • 黑客网站手机版b站软件推广大全
  • 网站优化三要素网站管理系统
  • 昆明公司做网站销售系统
  • 中国风网站模板下载新品推广计划与方案
  • 超能搜索引擎系统网站做网络推广的团队
  • zencart 网站老是跳转到原地址网页搜索引擎优化技术
  • 网络营销的网站建设报告百度新闻官网首页
  • 上海网站制作工具目前病毒的最新情况
  • h5网站架设免费的行情软件app网站
  • 郑州做网站元辰安徽网站建设优化推广
  • 怎么用网吧电脑做网站服务器最新军事战争新闻消息
  • 常州市做网站的公司最新新闻热点大事件
  • 品牌策划公司经营哪些内容seo搜索排名优化公司
  • 网站建设见站分析和准备论文最经典的营销案例
  • 延吉网站优化百度贴吧官网
  • 武汉做网站哪家好电子商务网站建设规划方案
  • 信息网络安全搜索引擎关键词优化
  • 长春哪有做网站公司百度知道问答
  • 如何建设微信商城网站网络营销渠道
  • 烟台哪个公司做网站好衡水网站优化推广
  • 诱人888网站百度指数使用方法
  • asp iis设置网站路径seo用什么工具
  • 网站建设 首选百川互动app推广是什么意思
  • 网站服务器维护方案微信公众号小程序怎么做
  • 网站运营及推广互联网销售平台有哪些