普通的队列是一种先进先出的数据结构,元素在队列尾追加,而从队列头删除。在优先队列中,元素被赋予优先级。当访问元素时,具有最高优先级的元素最先删除。优先队列具有最高级先出 (largest-in,first-out)的行为特征。STL中使用heap实现优先队列,底层容器使用的是vector。这里我.....
分类:
编程语言 时间:
2015-09-09 11:21:17
阅读次数:
286
problem:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.F...
分类:
其他好文 时间:
2015-09-08 15:14:43
阅读次数:
156
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find t...
分类:
其他好文 时间:
2015-09-08 12:01:12
阅读次数:
172
Maximum Product SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given...
分类:
其他好文 时间:
2015-09-07 12:33:10
阅读次数:
129
Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[?...
分类:
其他好文 时间:
2015-09-07 00:35:17
阅读次数:
147
给出一个有向图,求一个最大的结点集合,任意两个点u,v。u可到达v或v可到达u。一个强连通分量肯定一起选的。所以先找出所有scc,然后缩点以后跑DAG上的dp。注意0,0这组数据#includeusing namespace std;const int maxn = 1005,maxm = 5e5+...
分类:
其他好文 时间:
2015-09-02 00:32:12
阅读次数:
146
This link has a very neat code, which is rewritten below using stacksince thepushandpopoperations of it areO(1)time, while thepop_backandpush_backofve...
分类:
其他好文 时间:
2015-09-02 00:11:14
阅读次数:
208
DescriptionRain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 2 #include 3 #include 4 using namespace std; 5 #define N ....
分类:
其他好文 时间:
2015-08-31 23:14:10
阅读次数:
331
题目连接http://poj.org/problem?id=1753Flip GameDescriptionFlip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 sq...
分类:
其他好文 时间:
2015-08-31 17:04:21
阅读次数:
284
该题最直观的解决思路是先对数组进行排序,然后返回第k个元素即可,但是该方法的时间复杂度为 O(nlog(n)), 较高。比较高校的思路有两种:一种是堆排序的思路,一种是快拍的思路。
一、堆排序的思路。该思路设置容量为 k 的大顶堆,将剩余的元素每一个和堆顶元素进行比较,若比堆顶元素大则该元素必然不会是第 k 大的元素,直接处理下一个元素;若比...
分类:
其他好文 时间:
2015-08-29 17:04:59
阅读次数:
126