03 2020 档案
摘要:大整数的存储 我们可以定义一个结构体来存储: struct bigNum{ int d[1000]; //存储大整数 int len; //大整数的长度 bigNum() { memset(d, 0, sizeof(d)); len = 0; } }; 在我们输入大数时,一般先用字符串读入,然后再把
阅读全文
摘要:前言 对于1~n范围内素数的查找,我们常用的二重循环暴力算法的复杂度是O(n2),如果利用开根缩小范围的时间复杂度也无非是在O( n n n\sqrt n nn ),而,这些算法对于n在105以内都是可以接受的,但是如果需要更大范围的素数表,这些算法将显得力不从心。下面将介绍更加高效的算法。 埃氏
阅读全文
摘要:最大公约数 假设用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 =
阅读全文
摘要:1044 Shopping in Mars (25分) Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamon...
阅读全文
摘要:1085 Perfect Sequence (25分) Given a sequence of positive integers and another positive integer p. The sequence is said to be a per...
阅读全文
摘要:快速幂 首先,快速幂是用来解决什么问题的? 给定三个正整数a、b、m(a<109,b<1018,1<m<109),求ab%m 对于这个问题,如果使用暴力来处理显然是不行的,O(b)的复杂度支持b<108都已经很艰难了,更何况1018 快速幂的做法是基于二分的思想,因此也常称为二分幂。快速幂基于一下事
阅读全文
摘要:1038 Recover the Smallest Number (30分) Given a collection of number segments, you are supposed to recover the smallest number from...
阅读全文
摘要: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...
阅读全文
摘要:1037 Magic Coupon (25分) The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning...
阅读全文
摘要:1070 Mooncake (25分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of filling...
阅读全文
摘要:1048 Find Coins (25分) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she v...
阅读全文
摘要:1050 String Subtraction (20分) Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
阅读全文
摘要:1041 Be Unique (20分) Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule ...
阅读全文
摘要:1092 To Buy or Not to Buy (20分) Eva would like to make a string of beads with her favorite colors so she went to a small shop to b...
阅读全文
摘要:1084 Broken Keyboard (20分) On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters c...
阅读全文
摘要:1095 Cars on Campus (30分) Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times an...
阅读全文
摘要:1080 Graduate Admission (30分) It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applicati...
阅读全文
摘要:1083 List Grades (25分) Given a list of N student records with name, ID and grade. You are supposed to sort the records with respec...
阅读全文
摘要:1075 PAT Judge (25分) The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time y...
阅读全文
摘要:1055 The World's Richest (25分) Forbes magazine publishes every year its list of billionaires based on the annual ranking of the w...
阅读全文
摘要:1028 List Sorting (25分) Excel can sort records according to any column. Now you are supposed to imitate this function. Input Speci...
阅读全文
摘要:1025 PAT Ranking (25分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang U...
阅读全文
摘要:1062 Talent and Virtue (25分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about p...
阅读全文
摘要:1082 Read Number in Chinese (25分) Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chin...
阅读全文
摘要:1077 Kuchiguse (20分) The Japanese language is notorious for its sentence ending particles. Personal preference of such particles c...
阅读全文
摘要:1035 Password (20分) To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that th...
阅读全文
摘要:1073 Scientific Notation (20分) Scientific notation is the way that scientists easily handle very large numbers or very small numbe...
阅读全文
摘要:1061 Dating (20分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsf...
阅读全文
摘要:1058 A+B in Hogwarts (20分) If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as H...
阅读全文
摘要:1027 Colors in Mars (20分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a ...
阅读全文
摘要:1031 Hello World for U (20分) Given any string of N (≥5) characters, you are asked to form the characters into the shape of U. For ...
阅读全文
摘要:1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade of all the male students and the...
阅读全文
摘要:1065 A+B and C (64bit) (20分) Given three integers A, B and C in [−2^63,2^63], you are supposed to tell whether A+B>C. Input ...
阅读全文
摘要:1046 Shortest Distance (20分) The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t...
阅读全文
摘要:1042 Shuffling Machine (20分) Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techni...
阅读全文

浙公网安备 33010602011771号