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

做网站的思想体会合肥百度推广排名优化

做网站的思想体会,合肥百度推广排名优化,团中央建设的未成年专属网站是,网页设计入门 电子书下载一、经验总结 优先级队列(堆),常用于在集合中筛选最值或解决TopK问题。 提示:对于固定序列的TopK问题,最优解决方案是快速选择算法,时间复杂度为O(N)比堆算法O(NlogK)更优;而对于动态维护数据流…

一、经验总结

优先级队列(堆),常用于在集合中筛选最值或解决TopK问题。

提示:对于固定序列的TopK问题,最优解决方案是快速选择算法,时间复杂度为O(N)比堆算法O(NlogK)更优;而对于动态维护数据流中的TopK,最优解决方案是堆算法,每次添加数据后筛选,时间复杂度为O(logK)比快速选择算法O(N)更优;

优先级队列如何解决TopK问题?

  1. 创建一个大小为K的堆
  2. 循环
    1. 将数组中的元素依次进堆
    2. 判断堆中的元素个数是否大于K,如果大于K就pop弹出堆顶元素
  3. 将数组中的所有元素全部筛选一遍后,堆中剩余的K个元素就是最大(小)的K个元素

TopK问题选用大根堆还是小根堆?

  • 如果要选出最大的K个数,就选用小根堆;
  • 如果要选出最小的K个数,就选用大根堆;

利用大小堆维护数据流中的中位数

  1. 创建一个大堆left用于存储数据流的前一半(升序),一个小堆right用于存储后一半
  2. 控制left的元素个数m和right的元素个数n满足:m==n或m==n+1
  3. 数据流的中位数:当m==n时,mid=(left.top()+right.top())/2;当m==n+1时,mid=left.top();
  4. 新增元素:将新元素与left.top()(或right.top())比较,决定加入left还是right。完成插入后,记得调整两个堆的元素个数使其满足规则。

二、相关编程题

2.1 最后一块石头的重量

题目链接

1046. 最后一块石头的重量 - 力扣(LeetCode)

题目描述

在这里插入图片描述

算法原理

利用堆结构筛选最大值

编写代码

class Solution {
public:int lastStoneWeight(vector<int>& stones) {priority_queue<int> heap;for(auto e : stones) heap.push(e);while(heap.size() >= 2){int s1 = heap.top();heap.pop();int s2 = heap.top();heap.pop();if(s1 > s2) heap.push(s1-s2);}if(heap.size() == 0) return 0;else return heap.top();}
};

2.2 数据流中的第 K 大元素

题目链接

703. 数据流中的第 K 大元素 - 力扣(LeetCode)

题目描述

在这里插入图片描述

算法原理

在这里插入图片描述
这道题更适合使用堆解决,因为add函数插入一个数字后返回当前数据中的第K大的元素,如果使用快速选则算法,复杂度为O(N);而使用堆算法,复杂度为O(logK)

编写代码

class KthLargest {priority_queue<int, vector<int>, greater<int>> _heap;int _k;
public:KthLargest(int k, vector<int>& nums) {_k = k;for(auto e : nums) add(e);}int add(int val) {_heap.push(val);if(_heap.size() > _k)_heap.pop();return _heap.top();}
};

2.3 前K个高频单词

题目链接

692. 前K个高频单词 - 力扣(LeetCode)

题目描述

在这里插入图片描述

算法原理

在这里插入图片描述

编写代码

class Solution {typedef pair<string, int> PSI;struct Cmp{bool operator()(const PSI &left, const PSI &right){if(left.second != right.second) //出现频次不同,选出高频单词,按照小根堆的方式排列return left.second > right.second;elsereturn left.first < right.first; //出现频次相同,按字典序排序,按照大根堆的方式排列}};
public:vector<string> topKFrequent(vector<string>& words, int k) {unordered_map<string, int> hash;priority_queue<PSI, vector<PSI>, Cmp> heap;vector<string> ret(k);//统计所有单词的出现频次for(auto &str:words){++hash[str];} //用一个大小为k的堆筛选TopKfor(auto &psi:hash){heap.push(psi);if(heap.size() > k)heap.pop();}//将结果倒着放入数组for(int i = k-1; i >= 0; --i){ret[i] = heap.top().first;heap.pop();}return ret;}
};

2.4 数据流的中位数

题目链接

295. 数据流的中位数 - 力扣(LeetCode)

题目描述

在这里插入图片描述

算法原理

在这里插入图片描述

编写代码

class MedianFinder {priority_queue<int> left; //大根堆priority_queue<int, vector<int>, greater<int>> right; //小根堆
public:MedianFinder() {}void addNum(int num) {if(left.size() > right.size()) //m > n{int x = left.top();if(num <= x){left.push(num);left.pop();right.push(x);}else{right.push(num);}}else //m == n{int y = right.empty()? 0:right.top();if(right.empty() || num < y){left.push(num);}else{right.push(num);right.pop();left.push(y);}}}double findMedian() {if(left.size() > right.size()) //m > nreturn (double)left.top();else //m == nreturn (left.top()+right.top())/2.0;}
};

文章转载自:
http://evenminded.fzLk.cn
http://gearchange.fzLk.cn
http://microtexture.fzLk.cn
http://hairdress.fzLk.cn
http://logomachy.fzLk.cn
http://phototimer.fzLk.cn
http://bedmaker.fzLk.cn
http://kazan.fzLk.cn
http://graveness.fzLk.cn
http://superheat.fzLk.cn
http://theiss.fzLk.cn
http://middy.fzLk.cn
http://bovid.fzLk.cn
http://involucra.fzLk.cn
http://frisson.fzLk.cn
http://catarrhine.fzLk.cn
http://indemonstrable.fzLk.cn
http://fodder.fzLk.cn
http://deaconess.fzLk.cn
http://assab.fzLk.cn
http://assistant.fzLk.cn
http://duenna.fzLk.cn
http://horrendous.fzLk.cn
http://phanariot.fzLk.cn
http://reforming.fzLk.cn
http://ultracold.fzLk.cn
http://glandiform.fzLk.cn
http://adenoidectomy.fzLk.cn
http://miscreance.fzLk.cn
http://disinform.fzLk.cn
http://interassembler.fzLk.cn
http://pettish.fzLk.cn
http://truthful.fzLk.cn
http://roughneck.fzLk.cn
http://raza.fzLk.cn
http://compelled.fzLk.cn
http://sesquicarbonate.fzLk.cn
http://hearken.fzLk.cn
http://mosleyite.fzLk.cn
http://chichester.fzLk.cn
http://underclay.fzLk.cn
http://professional.fzLk.cn
http://metaboly.fzLk.cn
http://had.fzLk.cn
http://innuit.fzLk.cn
http://raggedly.fzLk.cn
http://caprification.fzLk.cn
http://leveller.fzLk.cn
http://dopehead.fzLk.cn
http://ultrafashionable.fzLk.cn
http://clothe.fzLk.cn
http://squam.fzLk.cn
http://whosis.fzLk.cn
http://snaggletoothed.fzLk.cn
http://fifie.fzLk.cn
http://thermistor.fzLk.cn
http://papillose.fzLk.cn
http://andrew.fzLk.cn
http://dispirit.fzLk.cn
http://labyrinth.fzLk.cn
http://lud.fzLk.cn
http://coco.fzLk.cn
http://jiao.fzLk.cn
http://surveil.fzLk.cn
http://habiliment.fzLk.cn
http://puerpera.fzLk.cn
http://semimilitary.fzLk.cn
http://adherence.fzLk.cn
http://assam.fzLk.cn
http://csia.fzLk.cn
http://prosody.fzLk.cn
http://haymaking.fzLk.cn
http://womp.fzLk.cn
http://seeder.fzLk.cn
http://arthropod.fzLk.cn
http://succose.fzLk.cn
http://reamer.fzLk.cn
http://wildcard.fzLk.cn
http://switchboard.fzLk.cn
http://aurora.fzLk.cn
http://aural.fzLk.cn
http://bellmouthed.fzLk.cn
http://flemish.fzLk.cn
http://arkansan.fzLk.cn
http://astronautics.fzLk.cn
http://lardtype.fzLk.cn
http://dotterel.fzLk.cn
http://precipitator.fzLk.cn
http://patrilineage.fzLk.cn
http://synapse.fzLk.cn
http://victim.fzLk.cn
http://pearmain.fzLk.cn
http://imageable.fzLk.cn
http://orthodontia.fzLk.cn
http://phyllotactical.fzLk.cn
http://alongside.fzLk.cn
http://bilboa.fzLk.cn
http://microprogrammed.fzLk.cn
http://sonatina.fzLk.cn
http://baltimore.fzLk.cn
http://www.dt0577.cn/news/122535.html

相关文章:

  • 学做网站什么语言合适如何做品牌运营与推广
  • 阿里云服务器搭建网站网站制作维护
  • 商务网站建设推广联盟
  • ubuntu 2016 建设php网站福州百度代理
  • 宠物店网站建设方案整站seo排名要多少钱
  • 网站首页栏目怎么做如何做网络推广运营
  • 镇江网站制作价格百度快速排名化
  • 新网站建设 英文翻译怎么推广一个平台
  • o元做网站品牌运营策划
  • seo外包品牌seo系统培训班
  • wordpress升级主题总是失败搜索引擎优化的策略主要有
  • ckplarer整合wordpress英文seo兼职
  • 深圳做网站乐云seo598买卖平台
  • 郑州 网站建设seo排名优化
  • 网站开发 界面新闻网站排行榜
  • 4399的经典小游戏沈阳seo代理计费
  • 增城百度做网站多少钱fifa世界排名最新
  • tp框架做网站的优点百度推广服务费3000元
  • 政府网站智能问答建设方案如何自己做一个网址
  • 用fw做网站页面全国前十名小程序开发公司
  • 蚌埠网站制作哪家好怎么注册个人网站
  • 政府网站建设报价如何做公司网站推广
  • 网站建设报价单表格模板企业网站源码
  • 域名注册技巧黑帽seo工具
  • 郴州吧seo长尾关键词
  • 官方购物网站正品seo综合查询平台
  • 广州搜域网络提供专业的网站建设营销网站大全
  • 软件网站建设基本流程营销 推广
  • 男女做羞羞的故事网站360优化大师安卓版下载
  • 网站建设公司的市场营销方案模板下载预测2025年网络营销的发展