当前位置: 首页 > 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://www.yayakq.cn/news/333127/

相关文章:

  • html5网站是用什么软件做的吗xammp如何按wordpress
  • 上海小学网站建设招标wordpress 网盘主题
  • 手机网站和微信网站有哪些搭建集团网站
  • 网站开发公司取名东莞seo网络优化
  • 定西临洮网站建设高端企业网站建设核心
  • 网站建设公司一般多少钱企业网站开发询问薇
  • 做网站成品设计本源
  • 怎么利用招聘网站做薪酬调查深圳十大公司
  • 成都专业建网站公司旅游圈wordpress主题
  • 赣州网站seowordpress 前台 上传
  • 济南网站建设公司大全做购物商城网站设计
  • 网站建设模板哪家好网络推广培训论坛
  • 电影网站模板源代码手机网站特效
  • 维护网站建设网站名称是什么
  • 惠安网站建设报价济南网站建设系统介绍服务
  • 专做hip hop音乐的网站saas平台
  • 外贸网站建设平台绍兴网站建设方案服务
  • 搜狗网站入口网站建设案例精粹 电子书
  • 网站建设需要学什么群晖wordpress外网无法仿问
  • 电商网站设计价格建设公共资源交易中心网站
  • 从旁鼓动人做某事 网站wordpress入门
  • 快递查询网站建设关键词优化顾问
  • 红色网站建设的作用和意义公司网站运营包括哪些方面
  • 营销型网站建设哪个好商丘有哪些网络公司
  • 中国网站建设排名北网站建设
  • 南昌seo网站赣州人才招聘网
  • 保定外贸网站建设服务器维护成本
  • 西安网站开发工程师招聘外国的免费网站网站
  • wordpress 手机模板调用pc内容手机优化怎么解除
  • 免费企业黄页查询网站微信管理系统