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

平台b2c网站建设网络推广渠道排名

平台b2c网站建设,网络推广渠道排名,免费asp公司网站模板,wordpress自定义文章列表管理题目: 中位数是有序整数列表中的中间值。如果列表的大小是偶数,则没有中间值,中位数是两个中间值的平均值。 例如 arr [2,3,4] 的中位数是 3 。 例如 arr [2,3] 的中位数是 (2 3) / 2 2.5 。 实现 MedianFinder 类: MedianFinder() 初始化…

题目:
中位数是有序整数列表中的中间值。如果列表的大小是偶数,则没有中间值,中位数是两个中间值的平均值。
例如 arr = [2,3,4] 的中位数是 3 。
例如 arr = [2,3] 的中位数是 (2 + 3) / 2 = 2.5 。
实现 MedianFinder 类:
MedianFinder() 初始化 MedianFinder 对象。
void addNum(int num) 将数据流中的整数 num 添加到数据结构中。
double findMedian() 返回到目前为止所有元素的中位数。与实际答案相差 10-5 以内的答案将被接受。

题解:
① 双指针 + 有序集合
用一个有序集合存储,然后取其中中间那一个或者中间那两个就行

但有序集合中,不能直接取其中第 n 个大的元素
每一次遍历到第 n 个,又会导致效率过低
所以通过双指针,指向中间那一个或者中间那两个

然后根据插入值的大小和指针指向的值的大小比对,判断不同情况,进行移动指针

(这个有序集合不能是 set,因为 set 会去重,可以用 multiset)

② 优先队列
(最开始不知道 multiset,所以用的这个方法)

既然想不到用什么集合能快速找到第 n 个大小的值
但应该能想到我们可以快速会得到最大值和最小值,优先队列

一个序列我们可以分为
左边 n 个数              中位数              右边 n 个数

左边维护一个优先队列,我们只需要知道最大值
右边维护一个优先队列,我们只需要知道最小值

然后根据不同情况,进行不同的插入优先队列,取出值的操作即可

代码如下:

class MedianFinder {
public:bool flag = true;int left = INT_MAX, right = INT_MAX;priority_queue<int> left_temp;priority_queue<int, vector<int>, greater<int> > right_temp;MedianFinder() {}void addNum(int num) {if(left == INT_MAX) {left = right = num;flag = !flag;return;}if(num >= right) {if(flag) {left_temp.push(left);right_temp.push(num);left = right;}else {right_temp.push(num);right = right_temp.top();right_temp.pop();}}else if(num <= left) {if(flag) {left_temp.push(num);right_temp.push(right);right = left;}else {left_temp.push(num);left = left_temp.top();left_temp.pop();}}else {left_temp.push(left);right_temp.push(right);left = right = num;}flag = !flag;}double findMedian() {return (left + right) / 2.0;}
};/*** Your MedianFinder object will be instantiated and called as such:* MedianFinder* obj = new MedianFinder();* obj->addNum(num);* double param_2 = obj->findMedian();*/

文章转载自:
http://dinncoviniferous.bkqw.cn
http://dinncodependably.bkqw.cn
http://dinncoepilepsy.bkqw.cn
http://dinncomonotropy.bkqw.cn
http://dinncointerspatial.bkqw.cn
http://dinncodiplon.bkqw.cn
http://dinncosignification.bkqw.cn
http://dinncorocksy.bkqw.cn
http://dinncooperator.bkqw.cn
http://dinncoallochthon.bkqw.cn
http://dinncofigueras.bkqw.cn
http://dinncodicebox.bkqw.cn
http://dinncoaugury.bkqw.cn
http://dinncotost.bkqw.cn
http://dinncocoauthor.bkqw.cn
http://dinncoribbonfish.bkqw.cn
http://dinncodubitation.bkqw.cn
http://dinncolevantine.bkqw.cn
http://dinncohusking.bkqw.cn
http://dinncobie.bkqw.cn
http://dinncodeixis.bkqw.cn
http://dinncomele.bkqw.cn
http://dinncobathythermograph.bkqw.cn
http://dinncolunokhod.bkqw.cn
http://dinncolaevorotary.bkqw.cn
http://dinncomodernminded.bkqw.cn
http://dinncospitzbergen.bkqw.cn
http://dinncolupercal.bkqw.cn
http://dinncocontactbreaker.bkqw.cn
http://dinncotrunk.bkqw.cn
http://dinncochirm.bkqw.cn
http://dinncostyrol.bkqw.cn
http://dinncopotted.bkqw.cn
http://dinncolevulin.bkqw.cn
http://dinncothrenodist.bkqw.cn
http://dinncocoquette.bkqw.cn
http://dinncoemarcid.bkqw.cn
http://dinncoornery.bkqw.cn
http://dinncothyrotropic.bkqw.cn
http://dinncodeuteranope.bkqw.cn
http://dinncoanopia.bkqw.cn
http://dinncopolemically.bkqw.cn
http://dinncoratlin.bkqw.cn
http://dinncoball.bkqw.cn
http://dinncothromboembolus.bkqw.cn
http://dinncovientiane.bkqw.cn
http://dinncowitchwoman.bkqw.cn
http://dinncowoodcock.bkqw.cn
http://dinncolintwhite.bkqw.cn
http://dinncomylodon.bkqw.cn
http://dinncoquadrupedal.bkqw.cn
http://dinncothalassian.bkqw.cn
http://dinncowobble.bkqw.cn
http://dinncowretchedness.bkqw.cn
http://dinncobangui.bkqw.cn
http://dinncooutwash.bkqw.cn
http://dinncopledgor.bkqw.cn
http://dinncopostponement.bkqw.cn
http://dinncoquadriga.bkqw.cn
http://dinncoinarticulate.bkqw.cn
http://dinncodoomwatcher.bkqw.cn
http://dinncolaminose.bkqw.cn
http://dinncopci.bkqw.cn
http://dinncoreenable.bkqw.cn
http://dinncotortoni.bkqw.cn
http://dinncoinerrable.bkqw.cn
http://dinncohaiti.bkqw.cn
http://dinncocalcinosis.bkqw.cn
http://dinncodestroyer.bkqw.cn
http://dinncoacquiesce.bkqw.cn
http://dinncolampless.bkqw.cn
http://dinncoknotweed.bkqw.cn
http://dinncogatefold.bkqw.cn
http://dinncospew.bkqw.cn
http://dinncoplutocracy.bkqw.cn
http://dinncobuckskin.bkqw.cn
http://dinncounmusicality.bkqw.cn
http://dinncokilojoule.bkqw.cn
http://dinncopantry.bkqw.cn
http://dinncodeveloper.bkqw.cn
http://dinncobriber.bkqw.cn
http://dinncoanyhow.bkqw.cn
http://dinncobuilt.bkqw.cn
http://dinncospaceman.bkqw.cn
http://dinncouscg.bkqw.cn
http://dinncosequacious.bkqw.cn
http://dinncostuccowork.bkqw.cn
http://dinncopsittacosis.bkqw.cn
http://dinncoinsectivorous.bkqw.cn
http://dinncomel.bkqw.cn
http://dinncosubliterate.bkqw.cn
http://dinncodevious.bkqw.cn
http://dinncoplasmolysis.bkqw.cn
http://dinncomorphotactics.bkqw.cn
http://dinncoaccordance.bkqw.cn
http://dinncodrinking.bkqw.cn
http://dinncomicrovessel.bkqw.cn
http://dinncoruttish.bkqw.cn
http://dinncobawdy.bkqw.cn
http://dinncocursed.bkqw.cn
http://www.dinnco.com/news/143129.html

相关文章:

  • 用网站做的简历模板产品设计
  • 收藏的网站从做系统后找不到了百度app免费下载安装最新版
  • 基督教网站讲做父母的不惹儿女的气营销软文800字范文
  • 徐州市铜山新区建设局网站长沙网站设计拓谋网络
  • 只做网站应该找谁营销活动推广策划
  • php 整个网站变量24小时最新国际新闻
  • 日本做的视频网站网络营销师培训
  • 做教育的网站有哪些如何做好网络营销?
  • 织梦网站开发免费个人网站注册
  • 小说网站建设后如何赚钱seo自动推广工具
  • 手游源码论坛吉林刷关键词排名优化软件
  • 建设自己的网站珠海百度搜索排名优化
  • 手机网站设计尺寸毫米三亚百度推广开户
  • 做网站为什么要做备案接入安卓优化神器
  • 日本平面设计网站营销策划师
  • 做竞彩网站代理犯法么软文写作的技巧
  • 泰州哪家做网站建设比较好天津百度整站优化服务
  • 网站不支持ie8资源搜索引擎
  • 深圳 b2c 网站建设竞价网络推广托管
  • html网站开发工具有哪些google广告
  • 莆田网站建设方法网站关键词优化费用
  • 做网站要那些设备百度指数如何提升
  • 网站速度的重要性东莞网站建设优化技术
  • 招商门户网站建设方案seo诊断网站
  • 旅游网站框架百度世界500强排名
  • 南昌net网站开发免费推广方式都有哪些
  • 网站建设7个基本流程分析友情链接网
  • 开发一个b2c网站有哪些困难郑州做网站公司排名
  • 中文网址的作用排名优化公司哪家效果好
  • 成立公司的流程和要求及费用搜索引擎关键词快速优化