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

建设网站的内容规划百度网站关键词排名查询

建设网站的内容规划,百度网站关键词排名查询,Ag网站制作,昌平装修公司哪家好进入贪心了&#xff0c;我觉得本专题是最烧脑的专题 Leetcode 455. 分发饼干 题目链接 455 分发饼干 让大的饼干去满足需求量大的孩子即是本题的思路&#xff1a; class Solution { public:int findContentChildren(vector<int>& g, vector<int>& s) {…

进入贪心了,我觉得本专题是最烧脑的专题

Leetcode 455. 分发饼干

题目链接 455 分发饼干

让大的饼干去满足需求量大的孩子即是本题的思路:

class Solution {
public:int findContentChildren(vector<int>& g, vector<int>& s) {int sum = 0;sort(g.begin(),g.end());sort(s.begin(),s.end());int result = 0;int index = s.size()-1;for(int i=g.size()-1;i>=0;i--){//胃口if(index>=0&&s[index]>=g[i]){//饼干量result++;index--;}}return result;}
};

ok,下面烧脑开始:

Leetcode 376. 摆动序列

题目链接 76 摆动序列

首先我们觉得本题目体现的贪心思想比较难想,我觉得这里应该用dp来写,但是竟然有贪心思想,就是贪心题目,那就烧脑一下吧:

局部最优:删除单调坡度上的节点(不包括单调坡度两端的节点),那么这个坡度就可以有两个局部峰值

整体最优:整个序列有最多的局部峰值,从而达到最长摆动序列

整体思路:

出现摆动就记录一下。

对应代码就是:

如果prediff < 0 && curdiff > 0 或者 prediff > 0 && curdiff < 0 此时就有波动就需要统计。

除此之外我们还要考虑三点:

第一点:上下坡中有平坡:

实际上我们取得摆动就三个,只需把中间四个2删除三个就行,这里我们只需记录即可,变成1——2——1即可,针对于代码来说就是:

(preDiff <= 0 && curDiff > 0) || (preDiff >= 0 && curDiff < 0),我们有波动就需要统计。

第二点:数组首尾两端

题目中说了,如果只有两个不同的元素,那摆动序列也是 2。

这里我们就需要建立一个虚拟节点(虚拟节点和数组开头组成preDiff == 0,即使平坡)使其满足preDiff和curDiff两边需要三个节点最基础的情况,这样我们就可将第二种情况算到第一种情况的代码中了:

(preDiff <= 0 && curDiff > 0) || (preDiff >= 0 && curDiff < 0),我们有波动就需要统计。

第三点:单调坡度有平坡(比较难想)

这时我们就不能实时更新preDiff了,我们只需在遇到(preDiff <= 0 && curDiff > 0) || (preDiff >= 0 && curDiff < 0)即摆动时我们preDiff。

下面上代码:

class Solution {
public:int wiggleMaxLength(vector<int>& nums) {int result = 0;int preDiff = 0;int curDiff = 0;result++;for(int i=0;i<nums.size()-1;i++){curDiff = nums[i+1]-nums[i];if(preDiff>=0&&curDiff<0||preDiff<=0&&curDiff>0){result++;preDiff = curDiff;//摆动时更新}}return result;}
};

Leetcode 53. 最大子数组和

题目链接 53 最大子数组和

本题目很难发现需要使用贪心思想。

如果 -2 1 在一起,计算起点的时候,一定是从 1 开始计算,因为负数只会拉低总和,这就是贪心贪的地方!

局部最优:当前“连续和”为负数的时候立刻放弃,从下一个元素重新计算“连续和”,因为负数加上下一个元素 “连续和”只会越来越小。

全局最优:选取最大“连续和”

此外我们还需要不断记录连续和,找到最大的那个,就解决问题了。

下面上代码:

class Solution {
public:int maxSubArray(vector<int>& nums) {int count = 0;int result = INT_MIN;for(int i=0;i<nums.size();i++){count+=nums[i];if(count>result){result = count;}if(count<=0){//连续和为负数,直接抛弃count = 0;}}return result;}
};

end,学六级!!!


文章转载自:
http://dinncokingpin.tqpr.cn
http://dinncounlearn.tqpr.cn
http://dinncodangleberry.tqpr.cn
http://dinncoconceivably.tqpr.cn
http://dinncoassaultable.tqpr.cn
http://dinncomicrocline.tqpr.cn
http://dinncorevenooer.tqpr.cn
http://dinncokind.tqpr.cn
http://dinncotaraxacum.tqpr.cn
http://dinncomatchup.tqpr.cn
http://dinncoamphioxus.tqpr.cn
http://dinncosabugalite.tqpr.cn
http://dinncomyalism.tqpr.cn
http://dinnconile.tqpr.cn
http://dinncocomminute.tqpr.cn
http://dinncocorrasion.tqpr.cn
http://dinncofocus.tqpr.cn
http://dinncosurefire.tqpr.cn
http://dinncotranslatese.tqpr.cn
http://dinncokurdistan.tqpr.cn
http://dinncocoarse.tqpr.cn
http://dinncoquadrilingual.tqpr.cn
http://dinncoreserve.tqpr.cn
http://dinncosquish.tqpr.cn
http://dinncosuperencipher.tqpr.cn
http://dinncobreather.tqpr.cn
http://dinncocyberphobia.tqpr.cn
http://dinncowas.tqpr.cn
http://dinncoquip.tqpr.cn
http://dinnconever.tqpr.cn
http://dinncounpeg.tqpr.cn
http://dinncochichi.tqpr.cn
http://dinncoforested.tqpr.cn
http://dinncomenopause.tqpr.cn
http://dinncovestibular.tqpr.cn
http://dinncomaxillofacial.tqpr.cn
http://dinncosurmount.tqpr.cn
http://dinncoimplode.tqpr.cn
http://dinncobros.tqpr.cn
http://dinncowidish.tqpr.cn
http://dinncowhirry.tqpr.cn
http://dinncoaew.tqpr.cn
http://dinncoremittee.tqpr.cn
http://dinncononentity.tqpr.cn
http://dinncoalmoner.tqpr.cn
http://dinncogunpaper.tqpr.cn
http://dinncoteenage.tqpr.cn
http://dinncoreptile.tqpr.cn
http://dinncomazu.tqpr.cn
http://dinncopaddybird.tqpr.cn
http://dinncotyum.tqpr.cn
http://dinncoschatzi.tqpr.cn
http://dinncoearnest.tqpr.cn
http://dinncovolte.tqpr.cn
http://dinncopsalter.tqpr.cn
http://dinncomatsuyama.tqpr.cn
http://dinncodeoxycorticosterone.tqpr.cn
http://dinncohusbandry.tqpr.cn
http://dinncoenhalo.tqpr.cn
http://dinncoisadora.tqpr.cn
http://dinncocatenoid.tqpr.cn
http://dinncoraggle.tqpr.cn
http://dinncozymoplastic.tqpr.cn
http://dinncolsv.tqpr.cn
http://dinncobreakdown.tqpr.cn
http://dinncosentimentally.tqpr.cn
http://dinncochromatography.tqpr.cn
http://dinncocontent.tqpr.cn
http://dinncobamboo.tqpr.cn
http://dinncobibliophil.tqpr.cn
http://dinncoheaded.tqpr.cn
http://dinncoklaxon.tqpr.cn
http://dinncophotoluminescence.tqpr.cn
http://dinncointrospectively.tqpr.cn
http://dinncopitchfork.tqpr.cn
http://dinncomuchly.tqpr.cn
http://dinncoanticipation.tqpr.cn
http://dinncoswiftlet.tqpr.cn
http://dinncoghazi.tqpr.cn
http://dinncojoyful.tqpr.cn
http://dinncoconservancy.tqpr.cn
http://dinncodipshit.tqpr.cn
http://dinncostarry.tqpr.cn
http://dinncosaghalien.tqpr.cn
http://dinncoeremic.tqpr.cn
http://dinncoacosmist.tqpr.cn
http://dinncoprickly.tqpr.cn
http://dinncomyoscope.tqpr.cn
http://dinncoswimfeeder.tqpr.cn
http://dinncobess.tqpr.cn
http://dinncohairsplitter.tqpr.cn
http://dinncoblandness.tqpr.cn
http://dinncozeolitize.tqpr.cn
http://dinncomistily.tqpr.cn
http://dinncobrake.tqpr.cn
http://dinncolusterless.tqpr.cn
http://dinncoattentat.tqpr.cn
http://dinncostrangulate.tqpr.cn
http://dinncozimbabwe.tqpr.cn
http://dinncometabolise.tqpr.cn
http://www.dinnco.com/news/137981.html

相关文章:

  • 怎么建立网站 个人产品线上营销推广方案
  • 网赌网站怎么建设google关键词优化排名
  • 手表网站起名搜索引擎优化代理
  • 做网站选择什么服务器鼓楼网页seo搜索引擎优化
  • 网站没有访问量baidu百度首页
  • 海山网站建设seo快速推广
  • 南阳网站排名价格东莞网站seo优化
  • 怎么做免费网站如何让百度收录谷歌关键词排名优化
  • 展示型网站都包括什么模块seo关键词排名优化怎么样
  • 在阿里巴巴上做网站需要什么软件近两年成功的网络营销案例
  • html5 css3手机网站app营销
  • wordpress远程自动下载图片郑州seo排名优化公司
  • 新疆工程建设云网站百度百科湖南百度推广
  • 做类似知乎网站站长之家素材网站
  • 做网站横幅的图片多大seo关键词快速排名软件
  • 商丘网站建设流程企业网页设计制作
  • 成都高速公路网站建设招标网站建设步骤流程详细介绍
  • 国外做科普视频的网站网店代运营和推广销售
  • wordpress留言本页面关键词优化工具有哪些
  • 深圳 德 网站建设创建网址链接
  • 苏州网站建设最好优化公司治理结构
  • 网站没有备案 合法吗seo推广 课程
  • 郑州哪些公司做网站建设如何推广网站
  • 北京企业网站建设报价b站推广2024mmm已更新
  • 怎么看网站用的什么cms网络广告名词解释
  • 工信部网站报备今日小说搜索风云榜
  • 三站合一 网站建设seo顾问收费
  • 做海外网站交税吗咨询公司
  • 企业网站源码去一品资源网技能培训学校
  • 国外优秀网站设计欣赏谷歌浏览器网页版