码迷,mamicode.com
首页 >  
搜索关键字:voting algorithm    ( 11828个结果
LeetCode - Best Time to Buy and Sell 3
这道题在前两个的基础上做稍微改进就可以。下面是AC代码: 1 /** 2 * Design an algorithm to find the maximum profit. You may complete at most two transactions. 3 * @pa...
分类:其他好文   时间:2014-07-22 23:01:13    阅读次数:251
[leetcode] Best Time to Buy and Sell Stock II
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a...
分类:其他好文   时间:2014-05-06 00:51:29    阅读次数:353
并查集类的c++封装,比较union_find algorithm四种实现方法之间的性能差别
并查集类的c++封装,比较union_find algorithm四种实现方法之间的性能差别...
分类:编程语言   时间:2014-05-05 21:25:44    阅读次数:324
[leetcode] Best Time to Buy and Sell Stock III
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a...
分类:其他好文   时间:2014-05-03 23:21:20    阅读次数:292
leetcode: Search a 2D Matrix
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l...
分类:其他好文   时间:2014-05-02 10:41:53    阅读次数:267
【CareerCup】Trees and Graphs—Q4.3
题目: Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height. 翻译: 给定一个有序数组(递增),写程序构建一棵具有最小高度的二叉树。 思路: 要使二叉树的高度最小,则要尽量使其左右子树的节点数目相当,自然就考虑到将其构造成为二叉排序树,且将有序数组的中间大的数作为根节点,这样得到的二叉树的高度便是最小的。...
分类:其他好文   时间:2014-05-01 17:48:45    阅读次数:321
堆排序
package algorithm.sort;public class HeapSort { public static void main(String[] args) { int[] a = new int[] {5, 3, 7, 2, 1, 4, 9, 8, 6, 1}; sort(a); p...
分类:其他好文   时间:2014-05-01 03:24:04    阅读次数:332
stable_sort() 和 sort() 的区别
1.stable_sort 和 sort的区别在于 前者作排序可以使原来的"相同"的值在序列中的相对位置不变 如 1 4 6 7 4' (4 和 4'值相等,加上' 表示是2个元素) 那么stable_sort能保证排序完 4 仍然在4' 前 也就是输出1 4 4' 6 7;但是sort 没有这个功能,算法不能保证这一点 2.在标准算法中的一部分算法 如果这个算法默认使用的是 ...
分类:其他好文   时间:2014-04-29 13:45:20    阅读次数:273
《Thinking in Algorithm》16.堆结构之斐波那契堆
前面的博客中我们讲到的堆的两种变体,二叉堆和二项堆,今天我们要讲的就是著名的斐波那契堆。二项堆和斐波那契堆对于search操作的支持均比较低效;可能花费一段时间才能找到关键字。为此,涉及给定元素的操作(如DECREASE-KEY和DELETE)均需要一个指针指向这个元素,并且指针作为输入的一部分。...
分类:其他好文   时间:2014-04-29 13:36:20    阅读次数:331
Timus 1510. Order 找到出现次数过半的数
又是一个新的算法,原来可以这样查找的。 我的一句话理解的思想: 计算可以抵消的数量,那么如果一个数出现的次数超过半那么最终这个数肯定不会被抵消完。 这个思想叫 Moore’s Voting Algorithm 有了这个思想武器之后,程序就可以写的很简单,可以很清楚看到怎么实现的, 参考资料可以看:...
分类:其他好文   时间:2014-04-29 13:22:22    阅读次数:260
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!