摘要:
将1……n的数表示成英文,求表示成这些英文的字母的和If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?NOTE:Do not count sp 阅读全文
摘要:
求2的1000次方的各个位置上的数的和215= 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.What is the sum of the digits of the number 21000?思想:普通算法肯定满足不了,只好自己实现大数算法,java的bigInteger应该可以做到这个吧,不过还是自己实现……构造一个334大的int数组,每一位存储最后计算结果的一个数值。只定义334个大小的数组的原因是因为在2的n次方最小最多3次就必须进一位,那么一位数最多可以保存2的三次方,所以取1000/3+1代码:private 阅读全文
摘要:
求格子的路径个数:Starting in the top left corner of a 22 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.How many such routes are there through a 2020 grid?思想:这是做了这么久之后我比较喜欢的一个题,终于要思考推一下下了。给格子上的顶点依次从(0,0)标起,往右或者往下两个数字依次加1,将题目的示例就可以转化为(0,0)->( 阅读全文
摘要:
这个星期重新整顿了一些基本查找排序算法的实现,我承认自己不是一个很灵光的码农,还搞了几个小时才把这些最基本的代码给码出来。。。查找:1、基本查找:针对无序的数组查找一般只有从头部(下标0)依次查找,如果查找成功返回数组下标,查找失败返回-1private static int commonSearch(int[] a, int b) { if (a == null) return -1; int len = a.length; for (int i = 0; i < len; i++) { if (a[i] ... 阅读全文
摘要:
求拉兹序列的最大链长:The following iterative sequence is defined for the set of positive integers:nn/2 (nis even)n3n+ 1 (nis odd)Using the rule above and starting with 13, we generate the following sequence:134020105168421It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. 阅读全文