浙江ACM竞赛试题200705
ACM题库完整版
#include<stdio.h> int type(int); char week[7][10]={"saturday","sunday","monday","tuesday","wednesday","thursday","friday"}; int year[2]={365,366}; int month[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31}; int main(void) { int days,dayofweek; int i=0,j=0; while(scanf("%d",&days)&&days!=-1) { dayofweek=days%7; for(i=2000;days>=year[type(i)];i++) days-=year[type(i)]; for(j=0;days>=month[type(i)][j];j++) days-=month[type(i)][j]; printf("%d-%02d-%02d%s\n",i,j+1,days+1,week[dayofweek]); } return 0; } int type(int m) { if(m%4!=0||(m%100==0&&m%400!=0)) return 0; else return 1; }
登山
1.题目描述 五一到了,NUIST-ACM队组织大家去登 山观光,队员们发现山上一个有N个景点, 并且决定按照顺序来浏览这些景点,即 每次所浏览景点的编号都要大于前一个 浏览景点的编号。同时队员们还有另一 个登山习惯,就是不连续浏览海拔相同 的两个景点,并且一旦开始下山,就不 再向上走了。队员们希望在满足上面条 件的同时,尽可能多的浏览景点,你能 帮他们找出最多可能浏览的景点数么? 2.输入 Line 1: N (2 <= N <= 1000) 景点数 Line 2: N个整数,每个景点的海拔 3.输出 最多能浏览的景点数 4.样例输入 8 186 186 150 200 160 130 197 220 5.样例输出 4
ACM软件大赛之编程大赛题目(附部分答案)
ACM 软件大赛之编程大赛比赛注意事项:l 比赛时间为3小时(小时(180180分钟);比赛分两个阶段:第一阶段限时30分钟,完成公示的3题,第二阶段限时150分钟(事先完成第一阶段题目的小组可提前进入第二阶段); l 比赛第一阶段的3道题目将在前期宣传中告知参赛选手,比赛第二阶段的题目将由赛事主席当场公布竞赛题目;主席当场公布竞赛题目;l 前两阶段题目分为三个分值(前两阶段题目分为三个分值(55分、分、1010分、分、1515分),第一阶段3道公示题都为5分;第二阶段总共15道题,根据不同的难度分值不同,分别为5道5分题,分题,55道10分题,分题,55道15分题;第一阶段参赛队员不可参考任何相关资料;第二阶段参赛队员可以携带诸如书,如书,手册,程序清单等参考资料。
手册,程序清单等参考资料。
手册,程序清单等参考资料。
比赛过程中队员不得携带任何电子媒质的资料;参比赛过程中队员不得携带任何电子媒质的资料;参赛者可以选择自己擅长的语言(赛者可以选择自己擅长的语言(C,C++,JAVA C,C++,JAVA 等等)进行编写等等)进行编写l 考虑到大一和大二学生的知识掌握程度,大一参加选手一开始就会有10分的分数,最后总分是由所做题目及初始的10分相加得到。
分相加得到。
l 每组队员根据安排使用电脑,小组人数为两人的使用一台电脑,超过两人的使用两台电脑,每台的电脑配置完全相同;脑,每台的电脑配置完全相同;l 各小组每做完一题或几题,必须交予评委老师运行,评委老师当场给分;各小组每做完一题或几题,必须交予评委老师运行,评委老师当场给分; l 如在比赛中发现作弊等行为,将取消比赛资格。
如在比赛中发现作弊等行为,将取消比赛资格。
第一阶段公示题目:题目一:(5分) 打印以下图形,纵遵从字母顺序,行字符数遵从斐波那契数列ABCCDDD EEEEEFFFFFFFFGGGGGGGGGGGGG#include<iostream>int f(int x){int a = 1 , b = 0;int max_ = x;int sum = 0; for(int i = 0; i < max_ ; i++){sum = a + b;a = b;b = sum;}return sum;}void loop_print(int num,char chr){for(int i = 0; i < num ;i++)std::cout<<chr;std::cout<<"\n";}int main(){int line_max = 7;char chr = 'A';for(int line = 0; line < line_max; line++){loop_print(f(line+1),chr);chr++;}return 0;}题目二:(5分)有个电子钟,12点显示为12:00(即12小时制),那么请问一天24时间内,出现连续3个相同数字的钟点有几个?#include<iostream>using namespace std;bool check(int me){int h= me/100;int m= me-100*h;return h<=12&&m<=59&&h>0?true:false;//12小时制小时制}int main(){int me=0;int j(0);//总计数器总计数器while( me<1270){//max 12:59int t= me;int n[4];for(int i=0;i<4;i++){n[i]=t%10;t /= 10;}if(n[1]==n[2]&&(n[0]==n[1]||n[3]==n[1])&&check( me)){//cout<<n[3]<<n[2]<<":"<<n[1]<<n[0]<<"\n";//testj++;me++;}cout<<"total: "<<j*2<<endl;}题目三:(5分)10进制的四位数中有几个符合如下特征:将其分别表示为16进制、10进制、12进制,在每种状态下,分别将各个位上的数相加,能得到3个相等10进制数。
ACM试题及参考答案
1. 给定一个矩阵M(X, Y),列集为X ,行集为Y 。
如果存在对其列的一个排序,使得每一行的元素都严格递增,称M 是一个次序保持矩阵。
例如下图中存在一个排序x 4,x 1,x 2,x 3,x 5I ⊆X ,满足:子矩阵M(I,Y)是次序保持矩阵。
[测试数据] 矩阵M :[测试数据结果] I={ x 1,x 3,x 4,x 7,x 8}[解题思路] 将该问题归约为在一个有向图中找一条最长路径的问题。
给定矩阵M=(a ij ),行集Y ,列集X ,行子集J ⊆Y ,定义有向图D A =(V A ,E A ),其中V A 含有|X|个顶点,每个顶点代表X 中的一列,如果顶点u ,v 对应的列x u ,x v 满足,对于任意的j ∈J ,u v ij ij a a <,则有一条从u 到v 的弧(u ,v )∈E 。
显然,D A 是个无环图,可以在O(|X|2)时间内构造完毕。
对于任意的条件子集J ,A(I,J)是次序保持的当且仅当对应于J 中条件的顶点在D A 中构成一条有向路径。
从而我们只需在有向图D A 中找一条最长路径,该问题可在O(|V A |+| E A |)时间内完成。
按上面的方法构造有向图如下:有向图中找最长路径的线性时间算法。
一些表示方法如下:d out (u )为顶点u 的出度,d in (u )为顶点u 的入度,source 为入度为0的顶点,sink 为出度为0的顶点,N out (u )为u 指向的邻接点集合,P uv 为从u 到v 的最长路,显然应从source 到sink 。
在每一步为每个顶点关联一个永久的或临时的标签。
v被赋了一个临时标签(v’,i v)表明在当前步,算法找出的最长的从source到v的有向路长度为i v,且经由v’而来。
v被赋了一个永久标签[v’,i v]表明从source到v的最长有向路长度为i v,且经由v’而来,通过回溯每个顶点的永久标签就可以找出最长有向路。
acm竞赛试题及答案
acm竞赛试题及答案ACM(Association for Computing Machinery)竞赛是一项全球性计算机科学竞赛,旨在锻炼参赛者的问题解决能力和编程技巧。
每年都有数千名来自不同学校的学生参加这一挑战。
本文将提供一些最近的ACM竞赛试题以及相应的答案,帮助读者了解和学习竞赛题目的类型和解题思路。
1. 问题描述给定一个由N个整数组成的数组A,请编写一个程序,找出数组中两个不同元素的差的最小值。
2. 输入格式- 第一行包含一个整数N,表示数组A的长度。
- 第二行包含N个以空格分隔的整数,表示数组A中的元素。
3. 输出格式输出一个整数,表示数组中两个不同元素的差的最小值。
4. 示例输入:51 52 9 12输出:15. 解题思路该问题可以通过对数组进行排序,并比较相邻两个数的差值来求解。
首先,将数组A进行升序排序。
然后,遍历排序后的数组,依次计算相邻两个数的差值,并记录其中的最小值。
最后,返回这个最小差值即可。
6. 代码实现```pythondef min_difference(nums):nums.sort() # 对数组进行升序排序min_diff = float('inf') # 初始化最小差值为正无穷大for i in range(len(nums)-1):diff = abs(nums[i] - nums[i+1]) # 计算相邻两个数的差值min_diff = min(min_diff, diff) # 更新最小差值return min_diff# 输入处理N = int(input())A = list(map(int, input().split()))# 调用函数并输出结果result = min_difference(A)print(result)```7. 答案解析对给定的数组进行排序后,遍历数组计算相邻两个数的差值,并记录其中的最小值。
上述代码中,首先将数组A进行升序排序,然后使用一个变量`min_diff`来记录最小差值。
(完整版)杭电acm部分答案
Problem DescriptionCalculate A + B.InputEach line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2#include<stdio.h>void main(){int a,b;while(scanf("%d %d",&a,&b)!=EOF){printf("%d\n",a+b);}}Problem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.InputThe input will consist of a series of integers n, one integer per line.OutputFor each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.Sample Input1100Sample Output15050#include<stdio.h>void main(){int n,sum,i;while(scanf("%d",&n)!=EOF){sum=0;for( i=0;i<=n;i++)sum+=i;printf("%d\n\n",sum);}}Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 +2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110 #include<stdio.h>#include<string.h>int main(){char str1[1001], str2[1001];int t, i, len_str1, len_str2, len_max, num = 1, k;scanf("%d", &t);getchar();while(t--){int a[1001] = {0}, b[1001] = {0}, c[1001] = {0};scanf("%s", str1);len_str1 = strlen(str1);for(i = 0; i <= len_str1 - 1; ++i)a[i] = str1[len_str1 - 1 - i] - '0';scanf("%s",str2);len_str2 = strlen(str2);for(i = 0; i <= len_str2 - 1; ++i)b[i] = str2[len_str2 - 1 - i] - '0';if(len_str1 > len_str2)len_max = len_str1;elselen_max = len_str2;k = 0;for(i = 0; i <= len_max - 1; ++i){c[i] = (a[i] + b[i] + k) % 10;k = (a[i] + b[i] + k) / 10;}if(k != 0)c[len_max] = 1;printf("Case %d:\n", num);num++;printf("%s + %s = ", str1, str2);if(c[len_max] == 1)printf("1");for(i = len_max - 1; i >= 0; --i){printf("%d", c[i]);}printf("\n");if(t >= 1)printf("\n");}return 0;}Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.Sample Input25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5Sample OutputCase 1:14 1 4Case 2:7 1 6注:最大子序列是要找出由数组成的一维数组中和最大的连续子序列。
浙江省程序设计大赛历年赛题解析V4.1
浙江省程序设计大赛 历年简单题解题分析V4.1 2008~2011软件技术教研室 程序设计兴趣小组 2011 年2 浙江省程序设计大赛历年简单题解题分析|Since2011-4-3目录 说明 ······················································································································ 3 版本更迭 ·············································································································· 3 2011 年第八届程序设计大赛 ·········································································· 4ORDINAL NUMBERS ······················································································································································· 6 CONIC SECTION ····························································································································································· 8 STRING SUCCESSOR ······················································································································································ 10 KAGOME KAGOME ······················································································································································· 13 JAVABEANS ································································································································································· 15 MEDIAN ···································································································································································· 172010 年第七届程序设计大赛 ······································································· 19WHO IS OLDER? ·························································································································································· 21 SOMALI PIRATES ·························································································································································· 23 AN AWFUL PROBLEM ··················································································································································· 25 WU XING ··································································································································································· 28 STRANGE COUNTRY II ··················································································································································· 30 GUESS THE PRICE ························································································································································· 342009 年第六届程序设计大赛 ······································································· 35SECOND-PRICE AUCTION ················································································································································37 LIGHT BULB ································································································································································ 40 CONNECT THEM ·························································································································································· 42 80ERS' MEMORY ························································································································································· 45 A STACK OR A QUEUE? ··················································································································································47 K-NICE ······································································································································································ 492008 年第五届程序设计大赛 ······································································· 51ACCURATELY SAY "COCACOLA"! ····································································································································· 53 BUILD THE ELECTRIC SYSTEM ········································································································································· 55 EASY TASK ···································································································································································57 FASTER, HIGHER, STRONGER ·········································································································································· 59 GIVE ME THE NUMBER ················································································································································· 61 KINDS OF FUWAS ························································································································································· 63 LIGHT BULBS ······························································································································································· 66浙江省程序设计大赛历年简单题解题分析|Since2011-4-33说明此文档只针对专科组学生需要解决的简单题进行分析,中等难度题不列入考虑。
2007ACM杯比赛往年试题集锦
A: 文本对齐time limit:5000msMemory limit:131072kBSubmissions:108Accepted:14题目描述HTML支持四种文本对齐方式:左对齐、右对齐、居中和两边对齐。
比较下面的例子:对齐方式例子左对齐Many years later, as he faced the firing squad, ColonelAureliano Buendiawas to remember that distant afternoon when his father tookhim to discoverice.右对齐Many years later, as he faced the firing squad, ColonelAureliano Buendia was to remember that distant afternoon when his father tookhim to discoverice.居中Many years later, as he faced the firing squad, ColonelAureliano Buendiawas to remember that distant afternoon when his father tookhim to discoverice.两边对齐Many years later, as he faced the firing squad, ColonelAureliano Buendiawas to remember that distant afternoon when his father tookhim to discoverice.文本模式浏览器通过在相邻单词之间插入空格来显示对齐文本。
在这里,但此就是由不是空格的字符组成的字符串。
现在你要来实现一个小程序来按下表指定的方式模仿文本模式浏览器在显示对齐文本时的行为。
2007浙江大学生高数竞赛真题(附答案)
2007浙江省高等数学(微积分)竞赛试题一、计算题(每小题12分,满分60分)1.求9解 原积分=55551155==3522(1)15x c + 2.求1120(1)(12)limsin x xx x x x→+-+解 由洛比塔法则,原极限=112220(1)ln(1)12(12)ln(12)lim (1)(12)(1)2(12)x xx x x x x x x x x x x x x →⎡⎤-++-+++-+⎢⎥++⎣⎦而20(1)ln(1)1lim(1)2x x x x x x →-++=-+ 2012(12)l n (12)l i m 12(12)x x x x x x →-++=-+ 2e∴原极限=3.求p 的值,使22007() ()0bx p ax p e dx ++=⎰解:当取p 满足()a p b p +=-+即2b ap +=-时 积分2222007()2007200722()0b a bb px p x x b a aa px p edx xe dx x e dx -++-+-+===⎰⎰⎰4.设(,)x ∀∈-∞+∞,''()0f x ≥,且20()1x f x e -≤≤-,求()f x 的表达式 解:由条件'()f x 单调增。
且(0)0f =易知'()0f x ≡,若不然,不妨设0x ∃ 0'()0f x >则当0x x >时0000()()'()'()()'()xxx x f x f x f x dx f x dx x x f x -=≥=-→+∞⎰⎰矛盾'()0f x ∴≤ 同理可让'()0'()0f x f x ≥⇒≡()(0)0f x f ∴≡='A'B 5.计算2()sx y dS+⎰⎰,其中S为圆柱面224x y+=,(0≤z≤1)解: S圆柱面关于y对称,且y是奇函数∴原积分=22221()2482s s sx ds y ds x y dsππ==+=⨯=⎰⎰⎰⎰⎰⎰二、(满分20)设1211211212345632313nun n n=+-++-+++---111123nvn n n=+++++求(1)1010uv(2)lim nnu→∞解:111121113()()32313323133n nnk kUk k k k k k k===+-=++-----∑∑111111111(32313123n nn k kVk k k k n n n===++-=+++=--++∑∑(1)10101UV=(2)22111111n nnk kUkn k nn====++∑∑21lim ln31nxU dxx→∞∴==+⎰三、(满分20分)有一张边长为4π的正方形纸(如图),C、D分别为'AA、'BB的中点,E为'DB的中点,现将纸卷成圆柱形,使A与'A重合,B与'B重合,并将圆柱垂直放在xoy平面上,且B与原点O重合,D落在Y轴正向上,此时,求:(1)通过C,E两点的直线绕Z轴旋转所得的旋转曲面方程;(2)此旋转曲面、xoy平面和过A点垂直于Z轴的平面所围成的立体体积。
(整理)ACM程序设计竞赛例题1.
备战ACM资料习题1. 0-1背包问题在0 / 1背包问题中,需对容量为c 的背包进行装载。
从n 个物品中选取装入背包的物品,每件物品i 的重量为wi ,价值为pi 。
对于可行的背包装载,背包中物品的总重量不能超过背包的容量,最佳装载是指所装入的物品价值最高。
程序如下:#include <stdio.h>void readdata();void search(int);void checkmax();void printresult();int c=35, n=10; //c:背包容量;n:物品数int w[10], v[10]; //w[i]、v[i]:第i件物品的重量和价值int a[10], max; //a数组存放当前解各物品选取情况;max:记录最大价值//a[i]=0表示不选第i件物品,a[i]=1表示选第i件物品int main(){readdata(); //读入数据search(0); //递归搜索printresult();}void search(int m){if(m>=n)checkmax(); //检查当前解是否是可行解,若是则把它的价值与max比较else{a[m]=0; //不选第m件物品search(m+1); //递归搜索下一件物品a[m]=1; //不选第m件物品search(m+1); //递归搜索下一件物品}}void checkmax(){int i, weight=0, value=0;for(i=0;i<n;i++){if(a[i]==1) //如果选取了该物品{weight = weight + w[i]; //累加重量value = value + v[i]; //累加价值}}if(weight<=c) //若为可行解if(value>max) //且价值大于maxmax=value; //替换maxvoid readdata(){int i;for(i=0;i<n;i++)scanf("%d%d",&w[i],&v[i]); //读入第i件物品重量和价值}void printresult(){printf("%d",max);}2.装载问题有两艘船,载重量分别是c1、c2,n个集装箱,重量是wi (i=1…n),且所有集装箱的总重量不超过c1+c2。
浙江大学ACM试题解答
}
int main()
{
int tmp,n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
if(m>n)
{
tmp=m ;
m=n ;
n=tmp;
}
flag1=flag2=0;
dfs(n,m,100);
if(flag1||!flag2)
Unfortunately, anyone who is willing to referee a game of crashing balloon is likely to get over-excited in the hot atmosphere that he\she could not reasonably be expected to perform the intricate calculations that refereeing requires. Hence the need for you, sober programmer, to provide a software solution.
--------------------------------------------------------------------------------
Submit Back Status
--------------------------------------------------------------------------------
On the other hand, if one player claims 162 points and the other claims 81, it is possible for both to be telling the truth (e.g. one crashes balloons 2, 3 and 27, while the other crashes balloon 81), so the challenge would not be upheld.
Acm试题及答案
Acm试题及答案1001 Sum Problem (2)1089 A+B for Input-Output Practice (I) (3)1090 A+B for Input-Output Practice (II) (5)1091A+B for Input-Output Practice (III) (7)1092A+B for Input-Output Practice (IV) (8)1093 A+B for Input-Output Practice (V) (10)1094 A+B for Input-Output Practice (VI) (12)1095A+B for Input-Output Practice (VII) (13)1096 A+B for Input-Output Practice (VIII) (15)2000 ASCII码排序 (16)2001计算两点间的距离 (17)2002计算球体积 (18)2003求绝对值 (20)2004成绩转换 (21)2005第几天? (22)2006求奇数的乘积 (24)2007平方与与立方与 (25)2008数值统计 (26)2009求数列的与 (27)2010水仙花数 (28)2011多项式求与 (30)2012素数判定 (31)2014青年歌手大奖赛_评委会打分 (32)2015偶数求与 (34)2016数据的交换输出 (36)2017字符串统计 (37)2019数列有序! (39)2020绝对值排序 (40)2021发工资咯:) (42)2033人见人爱A+B (43)2039三角形 (45)2040亲与数 (46)1001 Sum ProblemProblem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge)、In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + 、、、+ n、InputThe input will consist of a series of integers n, one integer per line、OutputFor each case, output SUM(n) in one line, followed by a blank line、You may assume the result will be in the range of 32-bit signed integer、Sample Input1100Sample Output15050AuthorDOOM III解答:#include<stdio、h>main(){int n,i,sum;sum=0;while((scanf("%d",&n)!=-1)){sum=0;for(i=0;i<=n;i++)sum+=i;printf("%d\n\n",sum);}}1089 A+B for Input-Output Practice(I)Problem DescriptionYour task is to Calculate a + b、Too easy?! Of course! I specially designed the problem for acm beginners、You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim、InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line、OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input、Sample Input1 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio、h>main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF)printf("%d\n",a+b);}1090 A+B for Input-Output Practice(II)Problem DescriptionYour task is to Calculate a + b、InputInput contains an integer N in the first line, and then N lines follow、Each line consists of a pairof integers a and b, separated by a space, one pair of integers per line、OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input、Sample Input21 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio、h>#define M 1000void main(){int a ,b,n,j[M],i;//printf("please input n:\n");scanf("%d",&n);for(i=0;i<n;i++){scanf("%d%d",&a,&b);//printf("%d %d",a,b); j[i]=a+b;}i=0;while(i<n){printf("%d",j[i]);i++;printf("\n");}}1091A+B for Input-Output Practice (III)Problem DescriptionYour task is to Calculate a + b、InputInput contains multiple test cases、Each test case contains a pair of integers a and b, one pair of integers per line、A test case containing 0 0 terminates the input and this test case is not to be processed、OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input、Sample Input1 510 200 0Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio、h>main(){int a,b;scanf("%d %d",&a,&b);while(!(a==0&&b==0)){printf("%d\n",a+b);scanf("%d %d",&a,&b);}}1092A+B for Input-Output Practice (IV)Problem DescriptionYour task is to Calculate the sum of some integers、InputInput contains multiple test cases、Each test case contains a integer N, and then N integers follow in the same line、A test case starting with 0 terminates the input and this test case is not to be processed、OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input、Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecommendJGShining解答:#include <stdio、h>int main(){int n,sum,i,t;while(scanf("%d",&n)!=EOF&&n!=0){sum=0;for(i=0;i<n;i++){scanf("%d",&t); sum=sum+t;}printf("%d\n",sum); }1093 A+B for Input-Output Practice (V)Problem DescriptionYour task is to calculate the sum of some integers、InputInput contains an integer N in the first line, and then N lines follow、Each line starts with a integer M, and then M integers follow in the same line、OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input、Sample Input24 1 2 3 45 1 2 3 4 5Sample Output1015Authorlcy解答:#include<stdio、h>main(){int n,a,b,i,j,sum;sum=0;while(scanf("%d\n",&n)!=-1){for(i=0;i<n;i++){scanf("%d",&b);for(j=0;j<b;j++){scanf("%d",&a);sum+=a;}printf("%d\n",sum); sum=0;}}}1094 A+B for Input-Output Practice(VI)Problem DescriptionYour task is to calculate the sum of some integers、InputInput contains multiple test cases, and one case one line、Each case starts with an integer N, and then N integers follow in the same line、OutputFor each test case you should output the sum of N integers in one line, and with one line of output for each line in input、Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecommendJGShining解答:#include<stdio、h>main(){int n,a,b,i,j,sum;sum=0;while(scanf("%d\n",&n)!=-1) {for(j=0;j<n;j++){scanf("%d",&a);sum+=a;}printf("%d\n",sum); sum=0;}}1095A+B for Input-Output Practice (VII)Problem DescriptionYour task is to Calculate a + b、InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line、OutputFor each pair of input integers a and b you should output the sum of a and b, and followed by a blank line、Sample Input1 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio、h>main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF)printf("%d\n\n",a+b);}1096 A+B for Input-Output Practice(VIII)Problem DescriptionYour task is to calculate the sum of some integers、InputInput contains an integer N in the first line, and then N lines follow、Each line starts with a integer M, and then M integers follow in the same line、OutputFor each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs、Sample Input34 1 2 3 45 1 2 3 4 53 1 2 3Sample Output10156AuthorlcyRecommendJGShining解答:int main(){int a,b,i,j,l[1000],k;scanf("%d",&i);getchar();for(j=1;j<=i;j++)l[j]=0;for(j=1;j<=i;j++){scanf("%d",&a);getchar();for(k=1;k<=a;k++){scanf("%d",&b);getchar();l[j]+=b;}}for(j=1;j<=i-1;j++)printf("%d\n\n",l[j]);printf("%d\n",l[i]);}2000 ASCII码排序Problem Description输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
acm数学竞赛试题及答案
acm数学竞赛试题及答案# 题目一:数列问题问题描述:给定一个数列 \( a_1, a_2, a_3, \ldots, a_n \),数列中每个元素都是正整数,且满足 \( a_i = a_{i-1} + a_{i-2} \) 对于所有\( i \geq 3 \)。
如果 \( a_1 = 1 \) 且 \( a_2 = 1 \),请找出数列的第 \( n \) 项。
解答:根据题意,这是一个斐波那契数列。
第 \( n \) 项的值可以通过递归关系计算得出。
对于 \( n \) 的值,可以使用以下递归公式:\[ a_n = a_{n-1} + a_{n-2} \]其中,\( a_1 = 1 \) 和 \( a_2 = 1 \)。
因此,数列的前几项为 1, 1, 2, 3, 5, 8, 13, 21, ...。
对于任意的 \( n \),可以通过递归或动态规划方法计算出 \( a_n \)。
# 题目二:组合问题问题描述:从 \( n \) 个不同的元素中选择 \( k \) 个元素的所有可能组合的个数是多少?解答:这个问题可以通过组合数学中的二项式系数来解决。
从 \( n \) 个不同元素中选择 \( k \) 个元素的组合数 \( C(n, k) \) 可以用以下公式计算:\[ C(n, k) = \frac{n!}{k!(n-k)!} \]其中,\( n! \) 表示 \( n \) 的阶乘。
# 题目三:几何问题问题描述:在一个直角坐标系中,给定三个点 \( A(x_1, y_1) \),\( B(x_2, y_2) \) 和 \( C(x_3, y_3) \)。
如果 \( \overrightarrow{AB} \) 和 \( \overrightarrow{AC} \) 是垂直的,求证 \( A \) 是直角三角形 \( ABC \) 的直角顶点。
解答:如果 \( \overrightarrow{AB} \) 和 \( \overrightarrow{AC} \) 垂直,那么它们的数量积(点积)应该为零。
浙江大学ACM题解分类
1475 Ranklist 没有完美解决,不知道您有没有好方法……
1572 Bracelet 题义不明,感觉可能是判定欧拉回路的存在性,但是过不去
动态规划:
1011 NTA 简单题
1013 Great Equipment 简单题
1024 Calendar Game 简单题
1027 Human Gene Functions 简单题
1239 Hanoi Tower Troubles Again! SRbGa的经典题……
字符串处理:
1050 Start Up the Startup 简单题
1315 Excuses, Excuses! 简单题
1350 The Drunk Jailer 简单题
1352 Number Base Conversion 简单题
1353 Unimodal Palindromic Decompositions 规模不大,所以是简单题……
1037 Gridland 简单题
1052 Algernon s Noxious Emissions 简单题
1409 Communication System 简单题,但是很容易看错~~~
1425 Crossed Matchings 简单题
1078 Palindrom Numbers 简单题
1086 Octal Fractions 简单题
1199 Point of Intersection 简单题
1104 Leaps Tall Buildings 简单题
1110 Dick and Jane 简单题
Acm试题及答案
Acm试题及答案1001 Sum Problem (2)1089 A+B for In put-Output Practice (I) (3)1090 A+B for In put-Output Practice (II) (4)1091 A+B for In put-Output Practice (III) (6)1092 A+B for Input-Output Practice (IV) (7)1093 A+B for In put-Output Practice (V) 9 1094 A+B for In put-Output Practice (VI) (11)1095 A+B for Input-Output Practice (VII) (12)1096 A+B for In put-Output Practice (VIII) (14)2000 ASCII 码排序 (15)2001计算两点间的距离 (16)2002计算球体积 (17)2003求绝对值 (18)2004成绩转换 (19)2005第几天? (20)2006求奇数的乘积 (22)2007平方和与立方和 (23)2008数值统计 (24)2009求数列的和 (25)2010水仙花数 (27)2011多项式求和 (28)2012素数判定 (29)2014青年歌手大奖赛—评委会打分 (31)2015偶数求和 (32)2016数据的交换输出 (34)2017字符串统计 (35)2019数列有序! (37)2020绝对值排序 (38)2021发工资咯:) (40)2033人见人爱A+B (41)2039三角形 (43)2040亲和数 (44)1001 Sum ProblemProblem Descripti onHey, welcome to HDOJ(Ha ngzhou Dianzi Uni versity On li ne Judge).In this problem, your task is to calculate SUM( n) = 1 + 2 + 3 + ... + n.In putThe in put will con sist of a series of in tegers n, one in teger per line.OutputFor each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit sig ned in teger.Sample In put1100Sample Output15050AuthorDOOM III解答:#i nclude<stdio.h>main (){int n , i , sum;sum =0;while (( scanf ("%d",& n)!=- 1)){sum =0;for (i =0; i <=n; i ++)sum +=i ;printf ("%d\n\n" , sum);}1089 A+B for In put-O utput Practice(I)Problem Descripti onYour task is to Calculate a + b.Too easy?! Of course! I specially desig ned the problem for acm beg inn ers.You must have found that some problems have the same titles with this one, yes, all these problems were desig ned for the same aim.In putThe in put will con sist of a series of pairs of in tegers a and b, separated by a space, one pair of in tegers per line.OutputFor each pair of in put in tegers a and b you should output the sum of a and b in one line, and with one line of output for each line in in put.Sample In put1 510 20Sample Output630AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>main (){int while printf a , b;(scanf ("%d%d",& a,& b)!= EOF) ("%d\n" , a+b);1090 A+B for In put-Output Practice(II)Problem Descripti onYour task is to Calculate a + b.In putIn put contains an in teger N in the first line, and the n N lines follow. Each line con sists of a pair of in tegers a and b, separated by a space, one pair of in tegers per line.OutputFor each pair of in put in tegers a and b you should output the sum of a and b in one line, and with one line of output for each line in in put.Sample In put21 510 20Sample Output630AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>#defi ne M 1000void mai n (){int a , b, n, j [ M], i ;//prin tf("please in put n:\n");scanf ("%d",& n);for (i =0; i <n; i ++){scanf ("%d%d",& a,& b);//prin tf("%d %d",a,b);j [ i ]= a+b;}i =0;while{ printf iprintf }}(i <n)("%d" , j [ i ]); ++;("\n");1091 A+B for In put-Output Practice (III)Problem Descripti onYour task is to Calculate a + b.In putIn put contains multiple test cases. Each test case contains a pair of in tegers a and b, one pair of in tegers per line. A test case containing 0 0 term in ates the in put and this test case is not to be processed.OutputFor each pair of in put in tegers a and b you should output the sum of a and b in one line, and with one line of output for each line in in put.Sample In put1 510 200 0Sample Output630AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>main (){int a , b;scanf ("%d %d",& a,& b); while (!( a==0&&b==0)){printf ("%d\n" , a+b);scanf ("%d %d",& a,&b);}}1092 A+B for Input-Output Practice (IV)Problem Descripti onYour task is to Calculate the sum of some in tegers.In putIn put contains multiple test cases. Each test case contains a in teger N, and the n N in tegers follow in the same line. A test case start ing with 0 term in ates the in put and this test case is not to be processed.OutputFor each group of in put in tegers you should output their sum in one line, and with one line of output for each line in in put.Sample In put4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecomme ndJGShi ning解答:#i nclude <stdio.h>int mai n (){int n , sum, i , t ;while (scanf ("%d" ,&n)!= EOF&&n!= 0){sum =0;for (i =0; i <n; i ++){scanf ("%d",& t);sum =sum+t ;("%d\n" , sum);} printf}1093 A+B for In put-Output Practice (V)Problem Descripti onYour task is to calculate the sum of some in tegers.In putIn put contains an in teger N in the first line, and the n N lines follow. Each line starts with a in teger M, and then M integers follow in the same line.OutputFor each group of in put in tegers you should output their sum in one line, and with one line of output for each line in in put.Sample In put24 1 2 3 45 1 2 3 4 5Sample Output1015Authorlcy解答:#i nclude<stdio.h>main (){int n , a, b, i , j , sum;sum =0;while ( scanf ("%d\n" ,& n)!=- 1){for (i =0; i <n; i ++){scanf ("%d",& b);for (j =0; j <b; j ++){scanf ("%d",& a);sum +=a;printf ("%d\n",sum);sum =0;}}}1094 A+B for Input-Output Practice(VI)Problem Descripti onYour task is to calculate the sum of some in tegers.In putIn put contains multiple test cases, and one case one line. Each case starts with an in teger N, and then N integers follow in the same line.OutputFor each test case you should output the sum of N in tegers in one line, and with one line of output for each line in in put.Sample In put4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>main (){int n , a, b, i , j , sum;sum =0;while ( scanf ("%d\n" ,& n)!=- 1) {for (j =0; j <n; j ++){scanf ("%d",& a);sum +=a;}printf ("%d\n" , sum);sum =0;}}1095 A+B for Input-Output Practice (VII)Problem Descripti onYour task is to Calculate a + b.In putThe in put will con sist of a series of pairs of in tegers a and b, separated by a space, one pair of in tegers per line.OutputFor each pair of in put in tegers a and b you should output the sum of a and b, and followed by a bla nk line.Sample In put1 510 20Sample Output630AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>main (){int a , b;while (scanf ("%d%d",& a,& b)!= EOF)printf ("%d\n\n" , a+b);}1096 A+B for In put-Output Practice(VIII)Problem Descripti onYour task is to calculate the sum of some in tegers.In putIn put contains an in teger N in the first line, and the n N lines follow. Each line starts with a in teger M, and then M integers follow in the same line.OutputFor each group of in put in tegers you should output their sum in one line, and you must note that there is a bla nk line betwee n outputs.Sample In put34 1 2 3 4Sample Output10156AuthorlcyRecomme ndJGShi ning 解答:int mai n (){a , b, i , j , l [ 1000], k;intscanf ("%d",& i );getchar ();for (j =1; j <=i ; j ++)l [ j ]= 0;for (j =1; j <=i ; j ++){scanf ("%d",& a);getchar ();for ( k=1; k<=a; k++){scanf ("%d",& b);getchar ();l [j]+=b;}}for (j =1; j <=i - 1; j ++)printf ("%d\n\n" , l [ j ]);printf ("%d\n" , l [ i ]);}2000 ASCII码排序Problem Descripti on输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
浙江大学acm答案完整版
浙江大学acm答案完整版求余运算给出S和M,求0*S%M,1*S%M,2*S%M......(M-1)*S%M能否组成一个集合包含0.1.。
M-1;(这个是原题意改造而来);算法:判断两个数是否互质;or 暴力解决其实暴力完全可以解决这个问题(⊙﹏⊙b),只是其中用数学方法更加高效,巧妙;证明如果S和M互质则满足题意:另G=gcd(S,M);则S=A*G,M=B*G;另X=K*S%M=K*S-T*M(T为整数,满足X属于0到M-1);X=K*A*G-T*B*G;因此取余后的整数一定是G的倍数,G只能取1才能满足条件;充分性的证明:(即当S与M互质,则0到M-1的S倍对M取余一定能遍历0到M-1)只需证明的是,该余数中两两之间互不相等;假设k*S和b*S对M取余相等(k和b∈[0,M),并且k和b不等);则k*S=q1*M+r=q2*M+r=b*S <==> (k-b)*S=M*(q1-q2);S与M互质,由上式子可得M|(k-b),与k和b∈[0,M),并且k和b不等矛盾;因此得证;另外,偶然看到一个很牛叉的辗转相除法;int gcd(int a,int b){while(b) b^=a^=b^=a%=b;return a;}此代码,很好很强大;把涉及位运算的交换的程序加入,便到得这段简洁高效的代码;注:A和B;经过A^=B^=A^=B,结果就得到A和B的交换//////////////////////////// 1000#includeint main(){int a,b,i,;scanf("%d",&a);for(i=1;i<=a;i++){ int sum=0;sum=sum+i;printf("%d\n",sum);}return 0;};1001;#include"stdio.h"int main(){unsigned _int64 n;unsigned _int64 temp;while(scanf("%I64u",&n)!=EOF) //是i 非L{temp=(1+n)*n/2;printf("%I64u\n\n",temp);}return 0;}//////////////////HDU ACM 1014 Uniform Generator 三月22nd, /doc/904868734.html,/showproblem.php?pid=1014这个题目是判断给定的步长和mod,判断所产生的随机数已经覆盖0~mod-1中所有的数,如果是,则说明所选的步长和mod是一个Good choice,否则为bad choice.需要懂得的基本内容为线性同余产生随机数,链接:/doc/904868734.html,/zh-cn/%E7%B7%9A%E6%80%A7%E5%90%8C%E9%A4%98%E6%96 %B9%E6%B3%95Problem DescriptionComputer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the formseed(x+1) = [seed(x) + STEP] % MODwhere '%' is the modulus operator.Such a function will generate pseudo-random numbers (seed) between 0 and MOD-1. One problem with functions of this form is that they will always generate the same pattern over and over. In order to minimize this effect, selecting the STEP and MOD values carefully can result in a uniform distribution of all values between (and including) 0 and MOD-1.For example, if STEP = 3 and MOD = 5, the function will generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a repeating cycle. In this example, all of the numbers between and including 0 and MOD-1 will be generated every MOD iterations of the function. Note that by the nature of the function to generate the same seed(x+1) every time seed(x) occurs means that if a function will generate all the numbers between 0 and MOD-1, it will generate pseudo-random numbers uniformly with every MOD iterations.If STEP = 15 and MOD = 20, the function generates the series0, 15, 10, 5 (or any other repeating series if the initial seed is other than 0). This is a poor selection of STEP and MOD because no initial seed will generate all of the numbers from 0 and MOD-1.Your program will determine if choices of STEP and MOD will generate a uniform distribution of pseudo-random numbers.InputEach line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).OutputFor each line of input, your program should print the STEP value right- justified in columns 1 through 10, the MOD value right-justified in columns 11 through 20 and either "Good Choice" or "Bad Choice" left-justified starting in column 25. The "Good Choice" message should be printed when the selection of STEP and MOD will generate all the numbers between and including 0 and MOD-1 when MOD numbers are generated. Otherwise, your program should print the message "Bad Choice". After each output test set, your program should print exactly one blank line.Sample Input3 515 2063923 99999Sample Output3 5 Good Choice15 20 Bad Choice63923 99999 Good Choice线性同余方法(LCG)是个产生伪随机数的方法。
acm初级试题及答案
acm初级试题及答案1. 问题描述给定一个整数数组,请找出数组中第二大的数。
2. 输入格式第一行包含一个整数N,表示数组中元素的数量。
第二行包含N个整数,用空格分隔。
3. 输出格式输出数组中第二大的数。
4. 样例输入51 2 3 4 55. 样例输出46. 问题分析要找出数组中第二大的数,首先需要对数组进行排序,然后取排序后的倒数第二个数。
7. 算法实现使用排序算法对数组进行排序,然后直接访问倒数第二个元素。
8. 代码实现```pythondef find_second_largest(N, nums):return nums[-2]# 读取输入N = int(input())nums = list(map(int, input().split()))# 输出结果print(find_second_largest(N, nums))```9. 注意事项- 确保输入的数组长度至少为2,否则无法找到第二大的数。
- 考虑数组中有重复元素的情况。
10. 测试用例- 输入:3 1 2 2输出:1- 输入:6 10 20 20 30 40输出:3011. 扩展问题如果要求找出数组中第二小的数,应该如何修改算法?12. 扩展问题答案- 修改算法,使其能够找到数组中第二小的数。
- 可以使用排序算法,然后取排序后的第一个元素。
13. 扩展问题代码实现```pythondef find_second_smallest(N, nums):return nums[1]# 读取输入N = int(input())nums = list(map(int, input().split()))# 输出结果print(find_second_smallest(N, nums)) ```。
ACM题库完整版
if(str[i]>='a'&&str[i]<='z') { str[i]=str[i]-32; } i++;
} puts(str); return 0; }
日历问题
1.题目描述 在我们现在使用的日历中, 闰年被定义为能被4整除的年份,但是能被100整除而不能被400整除的年 是例外,它们不是闰年。例如:1700, 1800, 1900 和 2100 不是闰年,而 1600, 2000 和 2400是闰年。 给定从公元2000年1月1日开始逝去的天数,你的任务是给出这一天是哪年哪月哪日星期几。 2.输入 输入包含若干行,每行包含一个正整数,表示从2000年1月1日开始逝去的天数。输入最后一行是?1, 不必处理。可以假设结果的年份不会超过9999。 3.输出 对每个测试样例,输出一行,该行包含对应的日期和星期几。格式为“YYYY-MM-DD DayOfWeek”, 其中 “DayOfWeek” 必须是下面中的一个: "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" 或 "Saturday“。 4.样例输入 1730 1740 1750 1751 -1 5.样例输出 2004-09-26 Sunday 2004-10-06 Wednesday 2004-10-16 Saturday 2004-10-17 Sunday 6.提示 2000.1.1. 是星期六
杭电ACM100题
杭电ACM100题题号 2000 ASCII 码排序 2002 计算球体积 2004 成绩转换 2006 求奇数的乘积 2008 数值统计 2010 水仙花数 2012 素数判定题名题号2001 计算两点间的距离2003 求绝对值2005 第几天?2007 平方和与立方和 2009 求数列的和 2011 多项式求和 2013 蟠桃记 2015 偶数求和 2017 字符串统计 2019 数列有序! 2021 发工资咯:)2023 求平均成绩 2025 查找最大元素 2027 统计元音题名2014 青年歌手大奖赛_评委会打分 2016 数据的交换输出 2018 母牛的故事 2020 绝对值排序 2022 海选女主角 2024 C 语言合法标识符2026 首字母变大写 2028 Lowest Common Multiple Plus 2030 汉字统计2032 杨辉三角2034 人见人爱A-B 2036 改革春风吹满地2038 test 2040 亲和数2042 不容易系列之二2044 一只小蜜蜂... 2046 骨牌铺方格 2048 神、上帝以及老天爷 2050 折线分割平面 2052 Picture 2054 A == B n 2056 Rectangles 2058 The sum problem 2060 Snooker 2062 Subset sequence 2064 汉诺塔 III 2066 一个人的旅行2068 RPG 的错排2070 Fibbonacci Number 2072 单词数2074 叠筐 2076 夹角有多大(题目已修改,注意读题) 2078 复习时间2029 Palindromes _easy version 2031 进制转换 2033 人见人爱A+B 2035 人见人爱 A^B 2037 今年暑假不 AC 2039 三角形 2041 超级楼梯 2043 密码 2045 不容易系列之(3)—— LELE 的 RPG 难题 2047 阿牛的EOF 牛肉串2049 不容易系列之(4)——考新郎2051 Bitset 2053 Switch Game 2055 An easy problem 2057 A + B Again 2059 龟兔赛跑 2061 Treasure the new start, freshmen! 2063 过山车 2065 "红色病毒"问题2067 小兔的棋盘2069 Coin Change 2071 Max Num 2073 无限的路 2075 A|B? 2077 汉诺塔 IV 2079 选课时间(题目已修改,注意读题)2080 夹角有多大 II 2082 找单词 2084 数塔 2086 A1 = n 2088 Box of Bricks 2090 算菜价 2092 整数解 2094 产生冠军 2096 小明A+B 2098 分拆素数和2081 手机短号 2083 简易版之最短距离 2085 核反应堆 2087 剪花布条2089 不要62 2091 空心三角形2093 考试排名2095 find your present (2) 2097 Sky 数 2099 整除的尾数。
acm试题及答案
acm试题及答案ACM试题及答案试题 1: 给定一个整数数组,请找出数组中第二大的数。
答案:1. 对数组进行排序。
2. 数组排序后,倒数第二个元素即为第二大的数。
试题 2: 编写一个函数,计算给定字符串中字符出现的次数。
答案:```pythondef count_characters(s):count_dict = {}for char in s:if char in count_dict:count_dict[char] += 1else:count_dict[char] = 1return count_dict```试题 3: 判断一个数是否为素数。
答案:1. 如果数小于2,则不是素数。
2. 从2开始到该数的平方根,检查是否有因数。
3. 如果没有因数,则该数是素数。
试题 4: 实现一个算法,将一个整数数组按照奇数在前,偶数在后的顺序重新排列。
答案:```pythondef rearrange_array(arr):odd = []even = []for num in arr:if num % 2 == 0:even.append(num)else:odd.append(num)return odd + even```试题 5: 给定一个链表,删除链表的倒数第n个节点。
答案:1. 遍历链表,找到链表的长度。
2. 再次遍历链表,找到倒数第n个节点的前一个节点。
3. 将前一个节点的next指针指向当前节点的下一个节点。
4. 如果当前节点是头节点,则更新头节点。
试题 6: 编写一个函数,实现字符串反转。
答案:```pythondef reverse_string(s):return s[::-1]```试题 7: 给定一个整数数组,找出数组中没有出现的最小正整数。
答案:1. 遍历数组,使用哈希表记录出现的数字。
2. 从1开始,检查每个数字是否在哈希表中。
3. 第一个不在哈希表中的数字即为答案。
试题 8: 实现一个算法,计算斐波那契数列的第n项。