码迷,mamicode.com
首页 >  
搜索关键字:递归 素数    ( 24700个结果
线性反馈移位寄存器与梅森旋转算法
今天主要是来研究梅森旋转算法,它是用来产生伪随机数的,实际上产生伪随机数的方法有很多种,比如线性同余法, 平方取中法等等。但是这些方法产生的随机数质量往往不是很高,而今天介绍的梅森旋转算法可以产生高质量的伪随 机数,并且效率高效,弥补了传统伪随机数生成器的不足。梅森旋转算法的最长周期取自一个梅森素数19937,由此 命名为梅森旋转算法。常见的两种为基于32位的MT19937-32和基于64位...
分类:其他好文   时间:2014-06-19 11:18:02    阅读次数:531
Combination Sum
题目 Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C un...
分类:其他好文   时间:2014-06-15 20:00:18    阅读次数:185
Combination Sum II
题目 Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in...
分类:其他好文   时间:2014-06-15 19:24:21    阅读次数:229
Count and Say
题目 The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 i...
分类:其他好文   时间:2014-06-15 18:51:33    阅读次数:220
HDu 2138 How many prime numbers 高效Miller素数测试
题目就是给出一组数,让我们测试其中有多少个是素数。 求素数有测试sqrt(n)个数的方法,有筛子方法,不过对于本题这样的题目来说就都不是高效的。 本题使用Miller Rabin素数测试法,效率奇高,对于不是极其大的整数测试都几乎是常数时间。令人神往的算法啊。 网上有个程序,好像是什么吉林的模板程序,不过我一直没看懂他是什么思路写的,是个AC的程序,不过却是错误的,呵呵,因为程序一直把9当做...
分类:其他好文   时间:2014-06-15 18:48:07    阅读次数:194
POJ 3664 Election Time 题解
这道题网上很多人都会说容易,水题之类的话,不过我看了下说这样的话的人的程序,可以说他们的程序都不及格! 为什么呢?因为他们的程序都是使用简单的二次排序水过(大概你能搜索到的多是这样的程序),那样自然可以说不及格了。 因为本题真正的目的是求前k个最大数的问题,这就需要活用快速排序。 求前k个最大数的思路: 1 选取一个数位轴,然后把大于这个数的数放到数列前面,小于这个数的数放到数列后面 2 如果前面的数的数量大于k,那么可以去掉后面的数,递归在前面的数查找前k个最大数 3 如果前面的数的数量小于k,那么截去前...
分类:其他好文   时间:2014-06-15 18:04:07    阅读次数:181
Search Insert Position
题目 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates i...
分类:其他好文   时间:2014-06-15 17:27:16    阅读次数:251
输入N个数,输出所有可能的排列组合(6+个小时啊,耶稣~)
输入N个数,输出所有可能的排列组合           一行代码一行泪。。。手都被发热的笔记本烤的不舒服了。。。。6个多小时过去鸟。。。终于粗来鸟。。。。 昨天同学问到一个排列组合的问题,本身不会很难,原题是固定输入4个数字,例如1 2 3 4,输出所有可能的排列组合 暴力的话应该不难的。代码+debug,半个小时。 如果是输入N个数字呢? 先说简单的暴力方法,如...
分类:其他好文   时间:2014-06-15 17:09:02    阅读次数:282
LeetCode:Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below bin...
分类:其他好文   时间:2014-06-15 09:34:35    阅读次数:226
[LeetCode] Subsets [31]
题目 Given a set of distinct integers, S, return all possible subsets. 原题链接(点我) 解题思路 子集合问题。给一个集合 ,求出其所有的子集合。这个题也是个组合问题--老思路:递归加循环。 代码实现......
分类:其他好文   时间:2014-06-13 21:28:42    阅读次数:252
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!