//max_heap heap_maximum:return A[1]    O(1); Extract_Heap_maximum:swap(A[1],A[heap.size])    adjust up to down from A[1] to hold the max_heap character   O(lgn)   every stepfind max child increase_Heap_max(i,key):[key>=A[i]],adjust down to up from A[…
常规方法 超时 class MedianFinder { vector<int> coll; public: MedianFinder(){ } void heapfu(vector<int>& coll,int idx,int max){ int left=2*idx+1,right=2*idx+2; int largest=idx; if(left<max&&coll[left]>coll[idx]) largest=left; if(rig…
装载自http://blog.csdn.net/tianshuai1111/article/details/7652553 一,概述 priority_queue是拥有权值观念的queue,它允许加入新元素,移除旧元素.调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法实现,也算是堆的另外一种形式.但它是一个queue所以只允许在底端加入元素,在顶端移除元素. 排序:按照权值大小顺序排序,而不是按照push 进去的顺序排序.权值高者排在前面,权值低…
STL序列式容器学习总结 参考资料:<STL源码剖析> 参考网址: Vector: http://www.cnblogs.com/zhonghuasong/p/5975979.html List: http://www.cnblogs.com/scandy-yuan/archive/2013/01/08/2851324.html Deque: http://blog.csdn.net/longshengguoji/article/details/8519812 1.Array array是C+…
数组中只出现一次的数字(一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字): 解法在于位运算中的异或,直接异或可以得到这两个数的异或,按照最后的有效数字位可以分为两个数组,然后分别异或得到各自的值: void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) { if(data.size()==0) return; *num1=0; *num2=0; vector<int> d…
heap并不是属于STL中的containers,而是在<algorithm>下提供了相关的函数 make_heap,sort_heap,pop_heap,push_heap 函数的说明: make_heap(_First, _Last, _Comp) 默认是建立最大堆的.对int类型,可以在第三个参数传入greater<int>() 得到最小堆,传入less<int>() 得到最大堆. max-heap是优先队列(priority queue)的底层实现机制 max-…
该题目与思路分析来自九章算法的文章,仅仅是自己做个笔记! 题目:数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数. 解答: 这道题是用堆解决的问题.用两个堆,max heap和min heap,再加一个median值,维持两个堆的大小相等(小根堆可以比大根堆多一个).对于新来的元素,比较新元素和median的大小,如果小于median就放入大根堆,如果大于median就放入小根堆里面,如果max heap和min heap不平衡了,就调整一下.然后调整过后的medi…
前言 前段时间装mysql,就遇到了ln: /usr/bin/mysql: Operation not permitted的错误,网上好多方法都过时了,下边是我的解决方法 原因 这是因为苹果在OS X 10.11中引入的SIP特性使得即使加了sudo(也就是具有root权限)也无法修改系统级的目录,其中就包括了/usr/bin.要解决这个问题有两种做法:一种是比较不安全的就是关闭SIP,也就是rootless特性:另一种是将本要链接到/usr/bin下的改链接到/usr/local/bin下就好…
异常处理汇总-开发工具  http://www.cnblogs.com/dunitian/p/4522988.html cleanup failed to process the following paths:xxx Previous operation has not finished; run 'cleanup' if it was interrupted 解决方法有两个,一个是用sqlite清除下数据库wc.db的work_queue,这种网上说的比较多.我说下第二种方法:这个需要svn…
MySQL字符串比较bug: select * from table_a a left join table_b b on a.field_a = b.field_b   error: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='   cause:两表编码方式不一致.   resolve:将比较等式的一边进行字符串转换,如:"CONVERT…