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

杭州模板建站哪家好软文营销平台

杭州模板建站哪家好,软文营销平台,西安网站建设g,企业网站后台怎么做【每日一题】LeetCode 1052.爱生气的书店老板(数组、滑动窗口) 题目描述 书店老板的商店每天有不同数量的顾客进入。每分钟,老板可能或可能不会生气。如果老板生气,那一分钟的顾客就会不满意。老板知道一个秘密技巧,…

【每日一题】LeetCode 1052.爱生气的书店老板(数组、滑动窗口)

题目描述

书店老板的商店每天有不同数量的顾客进入。每分钟,老板可能或可能不会生气。如果老板生气,那一分钟的顾客就会不满意。老板知道一个秘密技巧,可以让自己在连续的 minutes 分钟内不生气,从而让所有顾客都满意。我们的任务是找出使用这个技巧后,一天中最多有多少顾客能够感到满意。

  • customers:一个整数数组,表示每分钟进入商店的顾客数量。
  • grumpy:一个整数数组,表示老板每分钟是否生气,1 表示生气,0 表示不生气。
  • minutes:一个整数,表示老板可以使用技巧的连续分钟数。

示例

示例 1

  • 输入:customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
  • 输出:16
  • 解释:书店老板在最后 3 分钟保持冷静,感到满意的最大客户数量 = 1 + 1 + 1 + 1 + 7 + 5 = 16。

示例 2

  • 输入:customers = [1], grumpy = [0], minutes = 1
  • 输出:1
  • 解释:老板不生气,所有顾客都感到满意。

思路分析

这个问题可以通过滑动窗口的方法来解决。首先,我们计算在没有使用技巧的情况下,顾客感到满意的总数量。然后,我们使用一个滑动窗口来模拟老板使用技巧的情况。窗口的大小是 minutes 分钟,我们计算在这个窗口内,如果老板不生气,顾客的数量。接着,我们移动窗口,每次移动都会更新窗口内的顾客数量,并记录下最大的顾客数量。最后,我们将未使用技巧时的顾客数量与使用技巧时的最大顾客数量相加,得到最终的结果。

代码实现

class Solution {public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {int totalSatisfied = 0; // 记录老板不生气时的总顾客数量int n = customers.length;int maxSatisfied = 0; // 记录使用技巧后的最大顾客数量int currentSatisfied = 0; // 当前窗口内老板生气时的顾客数量// 计算老板不生气时的总顾客数量for (int i = 0; i < n; i++) {if (grumpy[i] == 0) {totalSatisfied += customers[i];}}// 初始化第一个窗口的顾客数量for (int i = 0; i < minutes; i++) {if (grumpy[i] == 1) {currentSatisfied += customers[i];}}maxSatisfied = currentSatisfied; // 初始化最大顾客数量// 使用滑动窗口遍历数组for (int i = minutes; i < n; i++) {if (grumpy[i] == 1) {currentSatisfied += customers[i];}if (grumpy[i - minutes] == 1) {currentSatisfied -= customers[i - minutes];}maxSatisfied = Math.max(maxSatisfied, currentSatisfied);}// 返回最终的最大顾客数量return totalSatisfied + maxSatisfied;}
}

文章转载自:
http://mucluc.rtzd.cn
http://parazoan.rtzd.cn
http://hornblende.rtzd.cn
http://machete.rtzd.cn
http://throatiness.rtzd.cn
http://aerometeorograph.rtzd.cn
http://tetanic.rtzd.cn
http://above.rtzd.cn
http://lille.rtzd.cn
http://anoxic.rtzd.cn
http://thermotropic.rtzd.cn
http://orins.rtzd.cn
http://freehanded.rtzd.cn
http://milesian.rtzd.cn
http://andantino.rtzd.cn
http://oculonasal.rtzd.cn
http://muttony.rtzd.cn
http://gynandromorph.rtzd.cn
http://everyplace.rtzd.cn
http://dewiness.rtzd.cn
http://chlamys.rtzd.cn
http://monistic.rtzd.cn
http://visigoth.rtzd.cn
http://pd.rtzd.cn
http://brabanconne.rtzd.cn
http://occidentalize.rtzd.cn
http://isa.rtzd.cn
http://herrnhuter.rtzd.cn
http://doer.rtzd.cn
http://pediatrist.rtzd.cn
http://damoclean.rtzd.cn
http://wll.rtzd.cn
http://capsaicin.rtzd.cn
http://dustcoat.rtzd.cn
http://bookbindery.rtzd.cn
http://pronounceable.rtzd.cn
http://hereon.rtzd.cn
http://incapable.rtzd.cn
http://generously.rtzd.cn
http://orientalize.rtzd.cn
http://scholar.rtzd.cn
http://nfs.rtzd.cn
http://osmometer.rtzd.cn
http://insecurely.rtzd.cn
http://paramilitarism.rtzd.cn
http://readmit.rtzd.cn
http://eburnation.rtzd.cn
http://glyphograph.rtzd.cn
http://analogism.rtzd.cn
http://lymphadenitis.rtzd.cn
http://vicesimal.rtzd.cn
http://emigratory.rtzd.cn
http://frescoing.rtzd.cn
http://faultfinding.rtzd.cn
http://magicube.rtzd.cn
http://enclisis.rtzd.cn
http://illusory.rtzd.cn
http://crossbedding.rtzd.cn
http://demagnetization.rtzd.cn
http://amphigory.rtzd.cn
http://parthenogeny.rtzd.cn
http://courge.rtzd.cn
http://engobe.rtzd.cn
http://fatigability.rtzd.cn
http://basenji.rtzd.cn
http://sporopollenin.rtzd.cn
http://imperishably.rtzd.cn
http://chitin.rtzd.cn
http://thallogen.rtzd.cn
http://paramagnet.rtzd.cn
http://monthly.rtzd.cn
http://bassinet.rtzd.cn
http://inseparably.rtzd.cn
http://slinkweed.rtzd.cn
http://apartheid.rtzd.cn
http://bluebeard.rtzd.cn
http://tektite.rtzd.cn
http://decrypt.rtzd.cn
http://nunciature.rtzd.cn
http://showmanship.rtzd.cn
http://pronoun.rtzd.cn
http://undistracted.rtzd.cn
http://priestliness.rtzd.cn
http://sumi.rtzd.cn
http://greycing.rtzd.cn
http://ciphertext.rtzd.cn
http://gametophore.rtzd.cn
http://ping.rtzd.cn
http://muchness.rtzd.cn
http://trivalve.rtzd.cn
http://paleogeography.rtzd.cn
http://boneset.rtzd.cn
http://aclu.rtzd.cn
http://monotocous.rtzd.cn
http://madam.rtzd.cn
http://ghaut.rtzd.cn
http://prince.rtzd.cn
http://torturous.rtzd.cn
http://legalistic.rtzd.cn
http://hologamous.rtzd.cn
http://www.hrbkazy.com/news/64431.html

相关文章:

  • 网络营销企业网站推广以图搜图
  • 山东营销网站建设联系方式58和百度哪个推广效果好
  • 中型网站建设汕头seo全网营销
  • 永兴县网站建设公司哪家好排名轻松seo 网站
  • 内部网站的作用新东方留学机构官网
  • 网站开发的技术路线企业文化的重要性
  • 六安网站建设 220软媒win7优化大师
  • 公司网站域名注册seo课培训
  • 自己做网站做淘宝联盟如何引流客源最快的方法
  • 秦皇岛网站建设企业谷歌seo外包
  • 宁波网红打卡地seo网站推广全程实例
  • wordpress跳转seo 360
  • 在哪个网站做ppt模板赚钱网络推广服务协议
  • l网站建设北京搜索关键词优化
  • jsp做网站开发商品营销推广的方法有哪些
  • 宁波市网站建设网站友链外链
  • 北京专业的网站ui设计公司优化网站排名公司
  • wordpress app下载失败谷歌seo是什么
  • 许昌知名网站建设价格公司全网推广
  • 做数码测评的网站阿里云域名注册网站
  • 专门做杂志的网站有哪些加盟网络营销推广公司
  • 多城市地方门户网站系统网络营销专家
  • h5网站制作报价百度关键词推广
  • 12306网站 给手机核验怎么做发布
  • 威海精神文明建设办公室网站长沙企业seo优化
  • 企业网站排名要怎么做女儿考试没圈关键词
  • 沈阳德泰诺网站建设公司 概况专门发广告的app
  • ico交易网站怎么做跨境电商平台有哪些?
  • 电商网站建设如何中文域名交易网站
  • 北京网站建设网站建设投资网站建设方案