上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 19 下一页
摘要: 1089 Insert or Merge (25分) According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growi... 阅读全文
posted @ 2020-04-10 17:40 Hu_YaYa 阅读(14) 评论(0) 推荐(0)
摘要: 1.扩展欧几里得算法 贝祖定理:若a,b是整数,且gcd(a,b)=d,那么对于任意的整数x,y,ax+by=m中的m一定是d的倍数。(特别地,如果a、b是整数,那么一定存在整数x、y使得ax+by=gcd(a,b)。) 那么贝祖定理的一个直接应用就是:如果ax+by=1有解,那么gcd(a,b)= 阅读全文
posted @ 2020-04-07 20:05 Hu_YaYa 阅读(577) 评论(0) 推荐(0)
摘要: 大整数的存储 我们可以定义一个结构体来存储: struct bigNum{ int d[1000]; //存储大整数 int len; //大整数的长度 bigNum() { memset(d, 0, sizeof(d)); len = 0; } }; 在我们输入大数时,一般先用字符串读入,然后再把 阅读全文
posted @ 2020-03-15 18:28 Hu_YaYa 阅读(183) 评论(0) 推荐(0)
摘要: 前言 对于1~n范围内素数的查找,我们常用的二重循环暴力算法的复杂度是O(n2),如果利用开根缩小范围的时间复杂度也无非是在O( n n n\sqrt n nn ​),而,这些算法对于n在105以内都是可以接受的,但是如果需要更大范围的素数表,这些算法将显得力不从心。下面将介绍更加高效的算法。 埃氏 阅读全文
posted @ 2020-03-14 11:07 Hu_YaYa 阅读(118) 评论(0) 推荐(0)
摘要: 最大公约数 假设用gcd(a,b)来表示a和b的最大公约数。 首先认识一个定理: 假设a、b均为正整数,则gcd(a, b) =gcd(b, a%b)。 证明: 设a = kb + r,其中k和r分别为a除以b得到的商和余数。 则有r = a - kb成立。 设d为a和b的一个公约数, 那么由r = 阅读全文
posted @ 2020-03-13 15:39 Hu_YaYa 阅读(26) 评论(0) 推荐(0)
摘要: 1044 Shopping in Mars (25分) Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamon... 阅读全文
posted @ 2020-03-11 17:56 Hu_YaYa 阅读(9) 评论(0) 推荐(0)
摘要: 1085 Perfect Sequence (25分) Given a sequence of positive integers and another positive integer p. The sequence is said to be a per... 阅读全文
posted @ 2020-03-11 13:35 Hu_YaYa 阅读(18) 评论(0) 推荐(0)
摘要: 快速幂 首先,快速幂是用来解决什么问题的? 给定三个正整数a、b、m(a<109,b<1018,1<m<109),求ab%m 对于这个问题,如果使用暴力来处理显然是不行的,O(b)的复杂度支持b<108都已经很艰难了,更何况1018 快速幂的做法是基于二分的思想,因此也常称为二分幂。快速幂基于一下事 阅读全文
posted @ 2020-03-10 22:16 Hu_YaYa 阅读(225) 评论(0) 推荐(0)
摘要: 1038 Recover the Smallest Number (30分) Given a collection of number segments, you are supposed to recover the smallest number from... 阅读全文
posted @ 2020-03-10 15:21 Hu_YaYa 阅读(22) 评论(0) 推荐(0)
摘要: 1067 Sort with Swap(0, i) (25分) Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasing ord... 阅读全文
posted @ 2020-03-10 14:42 Hu_YaYa 阅读(38) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 19 下一页