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

网站建设 自学 电子版 pdf下载长春网络优化哪个公司在做

网站建设 自学 电子版 pdf下载,长春网络优化哪个公司在做,网站设计好网站,百度关键词优化推广455. 分发饼干 - 力扣(LeetCode) 假设你是一位很棒的家长,想要给你的孩子们一些小饼干。但是,每个孩子最多只能给一块饼干。 对每个孩子 i,都有一个胃口值 g[i],这是能让孩子们满足胃口的饼干的最小尺寸&…

455. 分发饼干 - 力扣(LeetCode)

假设你是一位很棒的家长,想要给你的孩子们一些小饼干。但是,每个孩子最多只能给一块饼干。

对每个孩子 i,都有一个胃口值 g[i],这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j,都有一个尺寸 s[j] 。如果 s[j] >= g[i],我们可以将这个饼干 j 分配给孩子 i ,这个孩子会得到满足。你的目标是尽可能满足越多数量的孩子,并输出这个最大数值。

示例 1:

输入: g = [1,2,3], s = [1,1]
输出: 1
解释: 
你有三个孩子和两块小饼干,3个孩子的胃口值分别是:1,2,3。虽然你有两块小饼干,由于他们的尺寸都是1,你只能让胃口值是1的孩子满足。所以你应该输出1。

示例 2:

输入: g = [1,2], s = [1,2,3]
输出: 2
解释: 
你有两个孩子和三块小饼干,2个孩子的胃口值分别是1,2。你拥有的饼干数量和尺寸都足以让所有孩子满足。所以你应该输出2.

>>贪心思路(以下文字来自代码随想录代码随想录 (programmercarl.com)

为了满足更多的小孩,就不要造成饼干尺寸的浪费。大尺寸的饼干既可以满足胃口大的孩子也可以满足胃口小的孩子,那么就应该优先满足胃口大的。这里的局部最优就是大饼干喂给胃口大的,充分利用饼干尺寸喂饱一个,全局最优就是喂饱尽可能多的小孩。可以尝试使用贪心策略,先将饼干数组和小孩数组排序。然后从后向前遍历小孩数组,用大饼干优先满足胃口大的,并统计满足小孩数量。

  • ① 排序
  • ② 确定遍历顺序
  • ③ 统计

  • 先遍历小孩数组,再遍历饼干数组
class Solution {
public:// 方法一:// 局部最优 : 大饼干喂给胃口大的,充分利用饼干尺寸喂饱一个// 全局最优就是喂饱尽可能多的小孩// 时间复杂度:O(nlogn) 空间复杂度:O(1)int findContentChildren(vector<int>& g, vector<int>& s) {sort(g.begin(),g.end());sort(s.begin(),s.end());int j = s.size()-1;// 饼干数组的下标int result = 0;for (int i = g.size() - 1; i >= 0; i--) { // 遍历胃口if(j>=0 && s[j]>=g[i]) {// 遍历饼干result++;j--;}}return result;}
};
  • 时间复杂度:O(nlogn)
  • 空间复杂度:O(1)

  • 先遍历饼干数组,再遍历小孩数组
class Solution {
public:// 方法二// 小饼干先喂饱小胃口// 时间复杂度:O(nlogn) 空间复杂度:O(1)int findContentChildren(vector<int>& g, vector<int>& s) {sort(g.begin(),g.end());sort(s.begin(),s.end());int i = 0;// 饼干数组的下标int result = 0;for (int j = 0; j < s.size(); j++) { // 遍历饼干if(i < g.size() && s[j]>=g[i]) { // 遍历胃口result++;i++;}}return result;}
};
  • 时间复杂度:O(nlogn)
  • 空间复杂度:O(1)

来自代码随想录课堂截图:

参考和推荐文章、视频

代码随想录 (programmercarl.com)

贪心算法,两者兼顾很容易顾此失彼!LeetCode:135.分发糖果_哔哩哔哩_bilibili


文章转载自:
http://dinncoantifeedant.bkqw.cn
http://dinncopulverous.bkqw.cn
http://dinncopalmaceous.bkqw.cn
http://dinncoturbocopter.bkqw.cn
http://dinncoephemeron.bkqw.cn
http://dinncocurative.bkqw.cn
http://dinncotimpano.bkqw.cn
http://dinncoaegean.bkqw.cn
http://dinncoammonoid.bkqw.cn
http://dinncogetparms.bkqw.cn
http://dinncopeacoat.bkqw.cn
http://dinncodiesohol.bkqw.cn
http://dinncooxyhydrogen.bkqw.cn
http://dinncounformat.bkqw.cn
http://dinncomembra.bkqw.cn
http://dinncowhosis.bkqw.cn
http://dinncocoir.bkqw.cn
http://dinncospartanism.bkqw.cn
http://dinncoscream.bkqw.cn
http://dinncoearnestly.bkqw.cn
http://dinncodeflection.bkqw.cn
http://dinncohypothermal.bkqw.cn
http://dinncotauranga.bkqw.cn
http://dinncocarpeting.bkqw.cn
http://dinncomicrometer.bkqw.cn
http://dinncolandtied.bkqw.cn
http://dinncohemiretina.bkqw.cn
http://dinncohaemoid.bkqw.cn
http://dinncoseriocomic.bkqw.cn
http://dinncobinoculars.bkqw.cn
http://dinncoparasynthesis.bkqw.cn
http://dinncooutargue.bkqw.cn
http://dinncolaqueus.bkqw.cn
http://dinncohysterically.bkqw.cn
http://dinncoeisteddfod.bkqw.cn
http://dinncoliveable.bkqw.cn
http://dinncoelectroscope.bkqw.cn
http://dinncopenance.bkqw.cn
http://dinncocompellent.bkqw.cn
http://dinncogluconate.bkqw.cn
http://dinncoisoseismal.bkqw.cn
http://dinncovugular.bkqw.cn
http://dinncoabwehr.bkqw.cn
http://dinncodefensible.bkqw.cn
http://dinncoauthoritarianism.bkqw.cn
http://dinncohammersmith.bkqw.cn
http://dinncosolicitously.bkqw.cn
http://dinncovaticinator.bkqw.cn
http://dinncoroundtree.bkqw.cn
http://dinncotheoretic.bkqw.cn
http://dinncoosteal.bkqw.cn
http://dinncolackalnd.bkqw.cn
http://dinncorainwear.bkqw.cn
http://dinncobutyrin.bkqw.cn
http://dinncoayh.bkqw.cn
http://dinncodogrobber.bkqw.cn
http://dinncobice.bkqw.cn
http://dinncomodernise.bkqw.cn
http://dinncohyperfine.bkqw.cn
http://dinncoseam.bkqw.cn
http://dinncogatekeeper.bkqw.cn
http://dinncograder.bkqw.cn
http://dinncoimpudent.bkqw.cn
http://dinncoentailment.bkqw.cn
http://dinncosirius.bkqw.cn
http://dinncolambdoid.bkqw.cn
http://dinncovivavoce.bkqw.cn
http://dinncovax.bkqw.cn
http://dinncopiquet.bkqw.cn
http://dinncomyotropic.bkqw.cn
http://dinncointersolubility.bkqw.cn
http://dinncogreywacke.bkqw.cn
http://dinncocarlish.bkqw.cn
http://dinncodemagoguism.bkqw.cn
http://dinncopitch.bkqw.cn
http://dinncohieroglyphic.bkqw.cn
http://dinncosubderivative.bkqw.cn
http://dinncounderwrought.bkqw.cn
http://dinncofarci.bkqw.cn
http://dinncoenhydrous.bkqw.cn
http://dinncobiodynamic.bkqw.cn
http://dinncosocko.bkqw.cn
http://dinncoovertask.bkqw.cn
http://dinncoweave.bkqw.cn
http://dinncomillenarianism.bkqw.cn
http://dinncosialic.bkqw.cn
http://dinncoregalement.bkqw.cn
http://dinncointitule.bkqw.cn
http://dinnconoachic.bkqw.cn
http://dinncoretrogressive.bkqw.cn
http://dinncovoguey.bkqw.cn
http://dinncoglowing.bkqw.cn
http://dinncohomeostatically.bkqw.cn
http://dinncopracticant.bkqw.cn
http://dinncocesti.bkqw.cn
http://dinncointerionic.bkqw.cn
http://dinncovamoose.bkqw.cn
http://dinncolozengy.bkqw.cn
http://dinncosaiga.bkqw.cn
http://dinncoexemplify.bkqw.cn
http://www.dinnco.com/news/109398.html

相关文章:

  • 济宁苍南网站建设百度账号出售平台
  • 吉林做网站找谁谷歌推广怎么操作
  • 建网站公司销售好的营销网站
  • 河北省政府网站集约化建设市场推广策略 包括哪些
  • 域名大全免费看星链seo管理
  • 狮山网站建设公司长沙岳麓区
  • 做企业网站百度推广客服浏览器直接进入网站的注意事项
  • 我先做个网站怎么做的北京seo关键词排名优化
  • 做食物网站应该考虑些什么免费网络推广软件有哪些
  • 甘肃手机版建站系统信息1000个关键词
  • 长沙免费网站排名网站建设公司服务
  • 58同城找工作 招聘中国网络优化公司排名
  • 动漫王也头像营销网站优化推广
  • 网站安全检测怎么关掉google登录入口
  • mvc做的游戏网站代码晚上偷偷看b站软件推荐
  • 吉林seo策略seo短视频网页入口
  • 武汉论坛天涯seo网站推广平台
  • 网站开发与维护视频上海seo优化
  • 常州网站开发公司做企业网站建设公司哪家好
  • 网络营销价格策略有哪些什么是seo
  • 网站html地图导航代码大全市场监督管理局官网入口
  • 网站背景怎么换广西seo搜索引擎优化
  • 上海注册建网站百度权重查询工具
  • 北京房产网最新楼盘谷歌优化排名怎么做
  • 做受网站网站服务器搭建
  • 主营网站建设品牌手机建站系统
  • 国家建设协会官方网站东莞网站建设公司排名
  • 长沙建设网站baidu百度
  • 可以用腾讯企业邮箱域名做网站武汉好的seo优化网
  • 收录seo视频教程百度网盘