• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






dark_lake

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理
上一页 1 2 3 下一页

2013年5月17日

ProjectEuler 13
摘要: 就是大数相加,100个50位的数相加,取和的前10位Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.3710728753390210279879799822083759024651013574025046376937677490009712648124896970078050417018260538743249861995247410594742333095130581237266173096299194221336357416157252243056330181107 阅读全文
posted @ 2013-05-17 21:54 dark_lake 阅读(182) 评论(0) 推荐(0)
 
ProjectEuler 12
摘要: 求第一个有500个除数因子的三角数,具体题目见原文:The sequence of triangle numbers is generated by adding the natural numbers. So the 7thtriangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...Let us list the factors of the first seven triangle numbers:1 阅读全文
posted @ 2013-05-17 21:50 dark_lake 阅读(253) 评论(0) 推荐(0)
 

2013年5月11日

ProjectEuler 11
摘要: 对一个20*20的矩阵,求斜对角或者竖行或者横行连续4个数字的最大乘积思想:只会很笨的解法,读入文件到一个二维数组,然后对数组中的每个数字,进行4种可能的计算。。。官网没参考答案。。。代码:View Code 1 private static int gridproduct(String s) { 2 int product = 0; 3 int[][] a = readFile(s); 4 int rows = a.length; 5 int cols = a[0].length; 6 for (int i =... 阅读全文
posted @ 2013-05-11 22:03 dark_lake 阅读(191) 评论(0) 推荐(0)
 
KMP算法实现
摘要: 前面腾讯面试这题时,很多概念都搞混了,过来反省,好好研究了下KMP算法,把它实现。大体过程数据结构上都说得很明白,这里说说自己的感悟吧:主要是next数组的作用:现有一个主串s和模式串t,KMP算法会首先对模式串t求一个辅助数组next,有个这个next后我们每次匹配时主串的下标i就不用回溯,模式串的下标j回溯到next[j]的位置。看似next值越大越好,其实不是这样,next值当然是为0,为-1时最好。这个next数值k的意思表示当si!=tj时,那么tj-ktj-k+1...tj-1和主串的s0s1..sk-1是匹配的,那么其实需要回溯k位置,即主串回溯到i-k位置和t0比较。当然,由于 阅读全文
posted @ 2013-05-11 20:39 dark_lake 阅读(165) 评论(0) 推荐(0)
 
ProjectEuler 10
摘要: 求小于N的所有素数的和/** * The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. * * Find the sum of all the primes below two million. */思路:个人只会傻逼的遍历判断这个数是否为素数,然后迭加,代码如下:View Code private static long sumPrime(int N) { if (N < 2) return 0; if (N == 2) return 2; l... 阅读全文
posted @ 2013-05-11 20:02 dark_lake 阅读(243) 评论(0) 推荐(0)
 
ProjectEuler 9
摘要: 求和为1000毕达哥斯加三元组,其实就是余弦定理的三个数。。。A Pythagorean triplet is a set of three natural numbers, a b c, for * which, * * a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. * * There exists exactly one Pythagorean triplet for which a + b + c = 1000. * Find the product abc.思路:这道题木有什么好的思路,个人只会遍历,官网的方法... 阅读全文
posted @ 2013-05-11 19:46 dark_lake 阅读(124) 评论(0) 推荐(0)
 

2013年4月27日

ProjectEuler 8
摘要: 找出如下1000个整数中5个连续的数最大的乘积/** * Find the greatest product of five consecutive digits in the 1000-digit * number. * * 73167176531330624919225119674426574742355349194934 * 96983520312774506326239578318016984801869478851843 * 85861560789112949495459501737958331952853208805511 * 1254069874715852386... 阅读全文
posted @ 2013-04-27 15:57 dark_lake 阅读(132) 评论(0) 推荐(0)
 
ProjectEuler 7
摘要: 求第10001个素数/** * By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can * see that the 6th prime is 13. * * What is the 10 001st prime number? */代码:private static int nthPrime(int N) { if (N == 1) return 2; int k = 1; while (--N > 0) { k = k + 2; while (!isPrime(k)) ... 阅读全文
posted @ 2013-04-27 15:48 dark_lake 阅读(143) 评论(0) 推荐(0)
 
ProjectEuler 6
摘要: 求n个数和的平和与n的平方和的差/** * The sum of the squares of the first ten natural numbers is, * * 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural * numbers is, * * (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of * the squares of the first ten natural nu... 阅读全文
posted @ 2013-04-27 15:47 dark_lake 阅读(116) 评论(0) 推荐(0)
 
ProjectEuler 5
摘要: 求能够被1-20中任意一个数整除的最小正整数/** * 2520 is the smallest number that can be divided by each of the numbers * from 1 to 10 without any remainder. * * What is the smallest positive number that is evenly divisible by all of * the numbers from 1 to 20? */代码:private static long smallMul(int N) { long r =... 阅读全文
posted @ 2013-04-27 15:38 dark_lake 阅读(126) 评论(0) 推荐(0)
 
上一页 1 2 3 下一页