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

移动网站开发 王府井信息流广告是什么

移动网站开发 王府井,信息流广告是什么,重庆专业的网站建设公司,wordpress主题结合通过万岁!!! 题目:就是一个摩天轮,一共有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.hrbkazy.com/news/18935.html

相关文章:

  • 网站建设还有需求么2023知名品牌营销案例100例
  • 适合学生做网站的图片热点营销案例
  • 同一个服务器可以做多个网站数据分析师培训
  • 保定网站建设冀icp百度指数的数据来源
  • 企业网站的发展历史如何在国外推广自己的网站
  • 网站建设陆金手指下拉贰拾网上在哪里打广告最有效
  • 028网站建设工作室子域名大全查询
  • 中国wordpress变装关键词排名优化易下拉霸屏
  • 上海网站推广营销设计岳阳seo公司
  • 电商型企业网站建设长春网站建设公司哪个好
  • 网站建设问题及对策免费发布信息网平台
  • 设计logo的理念超级优化
  • 五级偏黄视频网站建设seo网络营销技巧
  • 庐山市星子网常用seo站长工具
  • 东莞网站建设.comqq群推广方法
  • 如何做企业套模网站计算机培训班有用吗
  • 国家认可提升学历正规机构seo和sem的区别与联系
  • 网站设计文档百度企业网盘
  • bootstrap企业网站模板产品宣传推广方式有哪些
  • 网站赏析案例网络营销与策划实践报告
  • 网站维护更新关键词排名点击工具
  • 沃尔玛网上商城app官方下载青岛网站seo诊断
  • 目前做系统比较好的网站地推拉新app推广接单平台免费
  • wordpress显示一个类目seo教程技术整站优化
  • 做网站要身份证吗如何查看网站收录情况
  • php制作网站用什么软件网络推广客服好做吗
  • 电影网站做流量站长工具无忧
  • 惠州做棋牌网站建设哪家服务好网站排行榜查询
  • 网络营销的六大新特征铁力seo
  • 深圳公司网站建设哪里专业搜索广告排名