第三届ACM程序设计大赛试题new
大学ACM考试题目及作业答案整理

ACM作业与答案整理1、平面分割方法:设有n条封闭曲线画在平面上,而任何两条封闭曲线恰好相交于两点,且任何三条封闭曲线不相交于同一点,问这些封闭曲线把平面分割成的区域个数。
#include <iostream.h>int f(int n){if(n==1) return 2;else return f(n-1)+2*(n-1);}void main(){int n;while(1){cin>>n;cout<<f(n)<<endl;}}2、LELE的RPG难题:有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.编程全部的满足要求的涂法.#include<iostream.h>int f(int n){if(n==1) return 3;else if(n==2) return 6;else return f(n-1)+f(n-2)*2;}void main(){int n;while(1){cin>>n;cout<<f(n)<<endl;}}3、北大ACM(1942)Paths on a GridTime Limit: 1000MS Memory Limit: 30000K DescriptionImagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b)2=a2+2ab+b2). So you decide to waste your time with drawing modern art instead.Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the left:Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?InputThe input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimension. Input is terminated by n=m=0.OutputFor each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how many paths are there on a grid where each step of the path consists of moving one unit to the right orone unit up? You may safely assume that this number fits into a 32-bit unsigned integer.Sample Input5 41 10 0Sample Output1262#include<iostream>using namespace std;longlong f(long long m, long long n){if(n==0) return 1;else return f(m-1,n-1)*m/n;}int main(){longlongm,n;while(scanf("%I64d %I64d",&n,&m) &&n+m){printf("%I64d\n",f(m+n,min(m,n)));}return 0;}1、(并查集)若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系。
中南大学第三届ACM校赛题目

Problem A. PalindromeDescriptionA palindrome is a symmetrical string, that is, a string read the same from left to right as from right to left. You are asked to write a program which, given a string, determines whether it is a palindrome or not.InputThe first line contain a single integer T, indicates the number of test cases.T lines follow, each line contain a string which you should judge. The length of the string is at most 1000.OutputPrint one line for each string, if it is a palindrome, output “YES”, else “NO”.Sample Input2abaabSample OutputYESNOProblem B. 素数槽Description处于相邻的两个素数p和p + n之间的n - 1个连续的合数所组成的序列我们将其称为长度为n的素数槽。
例如,‹24, 25, 26, 27, 28›是处于素数23和素数29之间的一个长度为6的素数槽。
你的任务就是写一个程序来计算包含整数k的素数槽的长度。
如果k本身就是素数,那么认为包含k的素数槽的长度为0。
Input第一行是一个数字n,表示需要测试的数据的个数。
后面有n行,每行是一个正整数k,k大于1并且小于或等于的第十万个素数(也就是1299709)。
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题

中原工学院第三届ACM大赛1. 春节将至,正是一年中铁路最繁忙的时候,大量出外打工的人们都在忙着返乡,小王就是其中的一个。
小王是河南郑州人,今年来到深圳打工的,第一次离开家乡,虽然挣了些钱,却来不及买什么东西,就想着回家看望家人以慰思乡之苦。
为了省钱,也为了避开人流,小王决定乘汽车回家。
从深圳到郑州,沿途经过很多站。
乘车方案是要么坐长途大巴,一站到家,但是可能比较贵。
要么中途在某些站下车进行中转,可能会比较省钱。
现在,小王搜集了沿途站点之间的票价,请你为小王编写一个程序,帮助他决策坐车的方案使花费最少。
设深圳到郑州间有n 个汽车站1,2,…,n,小王可以在任意站下车进行换乘。
在汽车站i到汽车站j 之间的票价为r(i,j),1≤i<j ≤n。
请编写程序,计算出从深圳汽车站(站1)到郑州汽车站(站n)所需的最少票价。
输入输入包含10组数据,每组数据的第 1 行中有 1 个正整数n (n<=200),表示从深圳到郑州途经n个汽车站。
接下来的n-1 行是r(i,j), 1≤i<j≤n。
输出程序运行结束时,输出深圳汽车站(站1)到郑州汽车站(站n)所需的最少票价。
样例输入35 157样例输出12(2). 小王今天参加驾照场地考试,考官看到小王各项测试都非常优秀,就特意为小王别出心裁设计了一个新测试项目。
这个新测试是这样的:将开阔的场地分成m×n的方格,每个方格占5×5米,如图所示,在这m×n个方格中有一些格子设置了障碍不许进入,而没有设置障碍的方格则可沿8个方向自由进入。
小王驾车初始位于场地的(p,q)方格中,他必须找出一条通向终点所在的(r,s)方格的路。
在抵达终点之前,他必须走遍所有未设置障碍的方格各一次,而且要使到达终点的转弯次数为最少。
每改变一次前进方向算作转弯一次。
请设计一个算法帮助小王找出这样一条道路,使小王通向终点的道路转弯最少。
输入输入包含多组数据。
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作业与答案整理1、平面分割方法:设有n条封闭曲线画在平面上,而任何两条封闭曲线恰好相交于两点,且任何三条封闭曲线不相交于同一点,问这些封闭曲线把平面分割成的区域个数。
#include <iostream.h>int f(int n){if(n==1) return 2;else return f(n-1)+2*(n-1);}void main(){int n;while(1){cin>>n;cout<<f(n)<<endl;}}2、LELE的RPG难题:有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.编程全部的满足要求的涂法.#include<iostream.h>int f(int n){if(n==1) return 3;else if(n==2) return 6;else return f(n-1)+f(n-2)*2;}void main(){int n;while(1){cin>>n;cout<<f(n)<<endl;}}3、北大ACM(1942)Paths on a GridTime Limit: 1000MS Memory Limit: 30000K DescriptionImagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b)2=a2+2ab+b2). So you decide to waste your time with drawing modern art instead.Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the left:Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?InputThe input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimension. Input is terminated by n=m=0.OutputFor each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how many paths are there on a grid where each step of the path consists of moving one unit to the right orone unit up? You may safely assume that this number fits into a 32-bit unsigned integer.Sample Input5 41 10 0Sample Output1262#include<iostream>using namespace std;long long f(long long m, long long n){if(n==0) return 1;else return f(m-1,n-1)*m/n;}int main(){long long m,n;while(scanf("%I64d %I64d",&n,&m) && n+m){printf("%I64d\n",f(m+n,min(m,n)));}return 0;}1、北大ACM(1012)JosephTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 31213 Accepted: 11700 DescriptionThe Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n, standing in circle every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give us the message about the incident. For example when n = 6 and m = 5 then the people will be executed in the order 5, 4, 6, 2, 3 and 1 will be saved.Suppose that there are k good guys and k bad guys. In the circle the first k are good guys and the last k bad guys. You have to determine such minimal m that all the bad guys will be executed before the first good guy.题目大意:编号为1,2…, n的n个人排成一圈,从第一个人开始,去掉后面的第m个人,在从第m+1个人开始去掉后面第m个人,以此类推。
第三届软件设计大赛本科组C语言题目全

1假设有两种微生物X 和YX出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍)。
一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y。
现在已知有新出生的X=10, Y=89,求60分钟后Y的数目。
如果X=10,Y=90 呢?本题的要求就是写出这两种初始条件下,60分钟后Y的数目。
题目的结果令你震惊吗?这不是简单的数字游戏!真实的生物圈有着同样脆弱的性质!也许因为你消灭的那只Y 就是最终导致Y 种群灭绝的最后一根稻草!请忍住悲伤,把答案写在“解答.txt”中,不要写在这里!2福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式:ABCDE * ? = EDCBA他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!”华生:“我猜也是!”于是,两人沉默了好久,还是没有算出合适的结果来。
请你利用计算机的优势,找到破解的答案。
把ABCDE 所代表的数字写出来。
答案写在“解答.txt”中,不要写在这里!3福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式:ABCDE * ? = EDCBA他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!”华生:“我猜也是!”于是,两人沉默了好久,还是没有算出合适的结果来。
请你利用计算机的优势,找到破解的答案。
把ABCDE 所代表的数字写出来。
答案写在“解答.txt”中,不要写在这里!4某电视台举办了低碳生活大奖赛。
题目的计分规则相当奇怪:每位选手需要回答10个问题(其编号为1到10),越后面越有难度。
答对的,当前分数翻倍;答错了则扣掉与题号相同的分数(选手必须回答问题,不回答按错误处理)。
每位选手都有一个起步的分数为10分。
某获胜选手最终得分刚好是100分,如果不让你看比赛过程,你能推断出他(她)哪个题目答对了,哪个题目答错了吗?如果把答对的记为1,答错的记为0,则10个题目的回答情况可以用仅含有1和0的串来表示。
acm大赛试题及答案

acm大赛试题及答案ACM大赛试题及答案1. 题目一:字符串反转问题描述:编写一个程序,输入一个字符串,输出其反转后的字符串。
输入格式:输入包含一个字符串,字符串长度不超过100。
输出格式:输出反转后的字符串。
示例:输入:hello输出:olleh答案:```pythondef reverse_string(s):return s[::-1]input_string = input().strip()print(reverse_string(input_string))```2. 题目二:计算阶乘问题描述:编写一个程序,输入一个非负整数n,输出n的阶乘。
输入格式:输入包含一个非负整数n,n不超过20。
输出格式:输出n的阶乘。
示例:输入:5输出:120答案:```pythondef factorial(n):if n == 0:return 1else:return n * factorial(n - 1)n = int(input())print(factorial(n))```3. 题目三:寻找最大数问题描述:给定一个包含n个整数的数组,找出数组中的最大数。
输入格式:输入包含一个整数n,表示数组的大小,随后是n个整数。
输出格式:输出数组中的最大数。
示例:输入:5 1 2 3 4 5输出:5答案:```pythonn = int(input())numbers = list(map(int, input().split()))max_number = max(numbers)print(max_number)```4. 题目四:判断闰年问题描述:编写一个程序,输入一个年份,判断该年份是否为闰年。
输入格式:输入包含一个整数,表示年份。
输出格式:如果输入的年份是闰年,则输出"Yes",否则输出"No"。
示例:输入:2000输出:Yes答案:```pythonyear = int(input())if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):print("Yes")else:print("No")```5. 题目五:斐波那契数列问题描述:编写一个程序,输入一个非负整数n,输出斐波那契数列的第n项。
第三届仲恺农业工程学院程序设计竞赛(ACM)试题

第三届仲恺农业工程学院程序设计竞赛(ACM)试题A.食物投放问题灾区已经非常困难,灾民需要帐篷、衣物、食品和血浆。
可通往灾区的道路到处都是塌方,70%以上的路面损坏,桥梁全部被毁。
中国空军立即启动应急预案,展开史上最大强度非作战空运行动,准备向灾区空投急需物资。
由于余震不断,天气恶劣,怎样知道空投的物资是否落在某灾区的区域内?经过空中观测,多数灾区为一圆形,空投的物资落在P(Xj,Yj)点。
你能否给出一个正确判断?【输入形式】第1行:M( M为空投的物资数)第2行:Xi0 Yi0 Ri(Xi0 ,Yi0)为圆心坐标,Ri为圆半径i=1, 2, …., N接下有M行:Xj Yij (Xj ,Yj)为空投物资的坐标j=1, 2, …., M )(输入数都为整数)【输出形式】输出有M行,每一行输出YES 或NO(若物资落在某个圆上或圆内,输出YES否则输出NO )【测试样例】B. 字符排列问题对于输入的字符,输出一共有多少种不同种排列方式,字符允许重复。
例如:AABC的全排列有:AABC 、AACB 、ABAC、ABCA、ACBA、ACAB、BAAC、BACA、BCAA、CBAA CABA、CAAB【输入形式】从标准输入字符字符【输出形式】输出一共有多少种不同的排列方式,在每一行末均输出一个回车符。
【测试样例】C.花费问题仲恺学院有很多女孩子都喜欢戴项链,这天,小胡来到魔法礼品店想买一串珍珠项链给一个女孩。
但当他看到珍珠项链时,他犯难了,因为有两串都很好看的珍珠项链摆在他眼前,他身上的钱的却只能购买一串。
环状的项链上串着白色的,黑色的和红色的珍珠,两个项链上总共的珍珠数是一样的,只是颜色和顺序不同,老板告诉小胡,只要小胡愿意,红色的珍珠可以变成白色的,也可以变成黑色的,可是黑白色的珍珠却不能变化。
于是,小胡想要一串能够变出更多类型的项链,(所谓两个项链类型不同,就是无论你怎么转动这两个项链,两个项链总有至少一个珍珠的颜色是不同的,如rbbb与bbrb是类型相同的,而rbbr与rbbb是类型不同的)他想那样更能讨她欢心,同时,他希望得到一个最长的相同颜色的子珍珠串,因为如果她不想戴着的话,小胡可能将项链剪断(最多只能剪两刀,即剪出来的相邻的珍珠在原来的项链上也是相邻的),剪出一串相同颜色的珍珠串送给她。
ACM校赛比赛题目及分析

Problem A -- 超级难题Time Limit:1000ms Memory Limit:65535KBDescriptionACM程序设计大赛是大学级别最高的脑力竞赛,素来被冠以"程序设计的奥林匹克"的尊称。
大赛自1970年开始至今已有30年历史,是世界范围内历史最悠久、规模最大的程序设计竞赛。
比赛形式是:经过校级和地区级选拔的参赛组,于指定的时间、地点参加世界级的决赛,由3个成员组成的小组应用一台计算机解决6到8个生活中的实际问题。
参赛队员必须在5小时内编完程序并进行测试和调试。
此种大赛对参赛学生的逻辑分析能力、策略制定和脑力方面具有极大的挑战性。
大赛提倡在压力较大的情况下,培养学生的创造力、团队合作精神以解决竞赛的问题,从而挑选和发掘世界上最优秀的程序设计人才竞赛的历史可以上溯到1970年,当时在美国德克萨斯A&M大学举办了首届比赛。
当时的主办方是the Alpha Chapter of the UPE Computer Science Honor Society。
作为一种全新的发现和培养计算机科学顶尖学生的方式,竞赛很快得到美国和加拿大各大学的积极响应。
1977年,在ACM计算机科学会议期间举办了首次总决赛,并演变成为目前的一年一届的多国参与的国际性比赛。
迄今已经举办了29届ACM/ICPC以团队的形式代表各学校参赛,每队由3名队员组成。
每位队员必须是入校5年内的在校学生。
比赛期间,每队使用1台电脑需要在5个小时内使用C、C++、Pascal或Java中的一种编写程序解决8或10个问题。
程序完成之后提交裁判运行,并把运行结果及时通知参赛队。
而且有趣的是每队在正确完成一题后,组织者将在其位置上升起一只代表该题颜色的气球2009年的时候队伍A参加了ACM的区域赛,那次区域赛比赛总共有N个题,队伍A做了N个题中的M个。
队伍A 做第一题所用的时间为T1分钟,做第一题所用的时间为T2分钟,.......做第M题所用的时间为Tm分钟。
acm编程比赛题

比赛试题主办方:迅翔计算机协会【问题描述】这是一个古老而又经典的问题。
用给定的几种钱币凑成某个钱数,一般而言有多种方式。
例如:给定了6种钱币面值为2、5、10、20、50、100,用来凑15元,可以用5个2元、1个5元,或者3个5元,或者1个5元、1个10元,等等。
显然,最少需要2个钱币才能凑成15元。
你的任务就是,给定若干个互不相同的钱币面值,编程计算,最少需要多少个钱币才能凑成某个给出的钱数。
【要求】【数据输入】输入可以有多个测试用例。
每个测试用例的第一行是待凑的钱数值M(1 <= M <= 2000,整数),接着的一行中,第一个整数K(1 <= K <= 10)表示币种个数,随后是K 个互不相同的钱币面值Ki(1 <= Ki <= 1000)。
输入M=0时结束。
【数据输出】每个测试用例输出一行,即凑成钱数值M最少需要的钱币个数。
如果凑钱失败,输出“Impossible”。
你可以假设,每种待凑钱币的数量是无限多的。
【样例输入】156 2 5 10 20 50 10011 2【样例输出】2Impossible【问题描述】Felicia 的生日是11月1日(和Kitty是同一天生的哦)。
于是Feli请来Kitty一起过生日。
Kitty带来了最新款的“Kitty猫”玩具准备送给Feli,不过她说,这份礼物可不是白送的。
Feli要帮她一个忙,才能够得到心仪已久的玩具。
Kitty说,“Kitty猫”玩具已经卖出了n!个,n<=10^100 *_*,Kitty想知道确切的数字,而不是无聊的“一个数加个感叹号”。
Feli 听了大吃一惊。
要知道,算出n!是一个无比艰巨的任务。
Feli告诉Kitty,就算Feli算出n!,Kitty也看不下去,因为当n=20 时,计算机的长整型已经存不下了(Kitty只能接受1-9之间的数字)。
于是Kitty说,你只要告诉我n!最后一位非0的数就可以了。
acm程序设计大赛试题

acm程序设计大赛试题ACM程序设计大赛试题是计算机科学领域中的一项重要竞赛活动,旨在选拔和培养具有优秀编程能力和创新思维的学生。
这项比赛既考察参赛选手解决实际问题的能力,又对他们的编程技巧、算法设计和计算机知识有着较高的要求。
本文将介绍ACM程序设计大赛试题的特点和题目类型。
一、ACM程序设计大赛试题的特点ACM程序设计大赛试题具有以下几个特点:1. 实际问题背景:ACM程序设计大赛试题往往以实际问题为基础,模拟真实世界中的场景,让选手能够将所学知识应用到实际中去。
2. 多样性:ACM程序设计大赛试题涵盖了多个领域的问题,如图论、动态规划、贪心算法等,选手需要具备广泛的知识储备和灵活的思维方式。
3. 时间限制:ACM程序设计大赛试题通常要求选手在有限的时间内解决问题,这既考验了选手对问题的理解能力,也考察了他们的编程速度和应变能力。
二、ACM程序设计大赛试题的题目类型ACM程序设计大赛试题的题目类型多种多样,以下是其中几个常见的类型:1. 编程题:选手需要根据题目要求,设计算法并编写代码解决问题。
这类题目旨在考察选手的编程能力和算法设计思维。
2. 选择题:选手需要在给定的选项中选择正确答案,这类题目常常涉及到基础的计算机知识和数据结构。
3. 填空题:选手需要根据题目要求,在给定的空格中填入适当的代码或数值,这类题目考察选手对编程语言和计算机原理的理解程度。
4. 简答题:选手需要对给定问题进行理论分析,并进行文字解释或证明,这类题目考察选手的理解能力和表达能力。
三、ACM程序设计大赛试题的难度ACM程序设计大赛试题的难度各有不同,通常分为初级、中级和高级三个层次,以满足不同年级和专业背景的选手需求。
初级试题注重基础知识和算法简单实现,中级试题涉及到较为复杂的数据结构和算法设计,高级试题则对选手的编程能力和创新思维提出更高要求。
四、参加ACM程序设计大赛的意义参加ACM程序设计大赛对学生有着重要的意义:1. 锻炼编程能力:参加ACM程序设计大赛能够提升选手的编程技巧和实际问题解决能力。
acm程序设计大赛题目

The Mailboxes Manufacturers ProblemTime Limit:1000MS Memory Limit:65536KTotal Submit:299 Accepted:227DescriptionIn the good old days when Swedish children were still allowed to blowup their fingers with fire-crackers, gangs of excited kids would plague certain smaller cities during Easter time, with only one thing in mind: To blow things up. Small boxes were easyto blow up, and thus mailboxes became a popular target. Now, a small mailbox manufacturer is interested in how many fire-crackers his new mailbox prototype can withstand without exploding and has hired you to help him. He will provide you with k(1 ≤ k≤ 10) identical mailbox prototypes each fitting up to m(1 ≤ m≤ 100) crackers. However, he is not sure of how many firecrackers he needs to provide you with in order for you to be able to solve his problem, so he asks you. You think for a while and then say, “Well,if I blow up a mailbox I can’t use it again, so if you would provide me with only k = 1 mailboxes, I would have to start testing with 1 cracker, then 2 crackers, and so on until it finally exploded. In the worst case, that is if it does not blow up ev en when filled with m crackers, I would need 1 + 2 + 3 + … + m = m ×(m+ 1) ⁄ 2 crackers. If m = 100 that would mean more than 5000 fire-crackers!” “That’s too many,” he replies. “What if I give you more than k = 1 mailboxes? Can you find a strategy that requires less crackers?”Can you? And what is the minimum number of crackers that you should ask him to provide you with?You may assume the following:1.If a mailbox can withstand x fire-crackers, it can also withstand x− 1fire-crackers.2.Upon an explosion, a mailbox is either totally destroyed (blown up) orunharmed, which means that it can be reused in another test explosion.Note: If the mailbox can withstand a full load of m fire-crackers, then the manufacturer will of course be satisfied with that answer. But otherwise he is looking for the maximum number of crackers that his mailboxes can withstand.InputThe input starts with a single integer N(1 ≤ N≤ 10) indicating the number of test cases to follow. Each test case is described by a line containing two integers: k and m, separated by a single space.OutputFor each test case print one line with a single integer indicating the minimum number of fire-crackers that is needed, in the worst case, in order to figure out how many crackers the mailbox prototype can withstand.Sample Input41 101 1003 735 100Sample Output555050382495SourceSvenskt Mästerskap i Programmering/Norgesmesterskapet 2002 #include <iostream>using namespace std;const int INF = 1 << 28;int d[11][101][101];int sum(int i, int j) {int ret = 0, k;for (k=i; k<=j; k++) ret += k;return ret;}int max(int a, int b) {return a > b ? a : b;}int main() {int caseTime;int i, j, k, t, K, M, l;scanf("%d", &caseTime);while (caseTime--) {scanf("%d%d", &K, &M);for (i=1; i<=M; i++) {for (j=i; j<=M; j++) {d[1][i][j] = sum(i, j);}}for (k=2; k<=K; k++) {for (l=0; l<M; l++) {for (i=1; i+l<=M; i++) {j = i + l;if (i == j) {d[k][i][j] = i;continue;}d[k][i][j] = INF;for (t=i; t<=j; t++) {int tmp;if (t == i) tmp = d[k][i+1][j];else if (t == j) tmp = d[k-1][i][j-1];else tmp = max(d[k-1][i][t-1], d[k-1][t+1][j]); tmp = max(d[k-1][i][t-1], d[k][t+1][j]);if (d[k][i][j] > t + tmp) d[k][i][j] = t + tmp; }}}}printf("%d\n", d[K][1][M]);}return 0;}Bugs Integrated, Inc.Time Limit:15000MS MemoryLimit:30000KTotal Submit:1180 Accepted:309 Case Time Limit:5000MSDescriptionBugs Integrated, Inc. is a major manufacturer of advanced memory chips. They are launching production of a new six terabyte Q-RAM chip. Each chip consists of six unit squares arranged in a form of a 2*3 rectangle. The way Q-RAM chips are made is such that one takes a rectangular plate of silicon divided into N*M unit squares. Then all squares are tested carefully and the bad ones are marked with a black marker.Finally, the plate of silicon is cut into memory chips. Each chip consists of 2*3 (or 3*2) unit squares. Of course, no chip can contain any bad (marked) squares. It might not be possible to cut the plate so that every good unit square is a part ofsome memory chip. The corporation wants to waste as little good squares as possible. Therefore they would like to know how to cut the plate to make the maximum number of chips possible.TaskYou are given the dimensions of several silicon plates and a list of all bad unit squares for each plate. Your task is to write a program that computes for each plate the maximum number of chips that can be cut out of the plate.InputThe first line of the input file consists of a single integer D (1 <= D <= 5), denoting the number of silicon plates. D blocks follow, each describing one silicon plate. The first line of each block contains three integers N (1 <= N <= 150), M (1 <= M <= 10), K (0 <= K <= MN) separated by single spaces. N is the length of the plate, M is its height and K is the number of bad squares in the plate. The following K lines contain a list of bad squares. Each line consists of two integers x and y (1 <= x <= N, 1 <= y <= M) ?coordinates of one bad square (the upper left square has coordinates [1, 1], the bottom right is [N,M]).OutputFor each plate in the input file output a single line containing the maximum number of memory chips that can be cut out of the plate.Sample Input26 6 51 44 62 23 66 46 5 43 36 16 26 4Sample Output34SourceCEOI 2002CODE:#include <iostream>using namespace std;int g[150][10], blk[10];int d[4][60000];int e[11] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049};int n, m, kn;int can1, can2, b[10][60000];int *l0, *l1, *l2, *l3, *bit0, *bit1, *bit2;void build() {int i, j, tmp;for (i=0; i<e[10]; i++) {j = 0; tmp = i;while (tmp > 0) {b[j][i] = tmp % 3;tmp /= 3;j++;}}}inline int maxt(int a, int b) {return a > b ? a : b;}void solve() {int i, j, k, x, y, a1, a2, p, c;scanf("%d%d%d", &n, &m, &kn);memset(g, 0, sizeof(g));memset(d, 0, sizeof(d));for (i=0; i<kn; i++) {scanf("%d%d", &x, &y);g[x-1][y-1] = 1;}for (i=0; i<m; i++) blk[i] = 1 - g[0][i];for (i=1, c=2; i<n; i++) {for (j=0; j<m; j++) {if (g[i][j]) blk[j] = 0;else blk[j]++;c = (c+1)%4;can1 = (j>0 && blk[j]>2 && blk[j-1]>2);can2 = (j>1 && blk[j]>1 && blk[j-1]>1 && blk[j-2]>1);a1 = 2*e[j]+2*e[j-1];a2 = e[j]+e[j-1]+e[j-2];l0 = d[c]; l1 = d[(c+3)%4]; l2 = d[(c+2)%4]; l3 = d[(c+1)%4];bit0 = b[j];if (j>0) bit1 = b[j-1];if (j>1) bit2 = b[j-2];for (p=0; p<e[m]; p++) {if (bit0[p]) {l0[p] = l1[p-e[j]];} else {l0[p] = l1[p];if (j>0 && !bit1[p]) {if (can1) l0[p] = maxt(l0[p],l2[p+a1]+1);if (can2 && !bit2[p]) l0[p] = maxt(l0[p], l3[p+a2]+1); }}}}}printf("%d\n", d[c][0]);}int main() {build();int caseTime;scanf("%d", &caseTime);while (caseTime--) {solve();}return 0;}Silver Cow PartyTime Limit:2000MS MemoryLimit:65536KTotal Submit:1112 Accepted:326 DescriptionOne cow from each of N farms (1 ≤ N≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X(1 ≤ X≤ N). A total of M (1 ≤ M≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires T i(1 ≤ T i≤ 100) units of time to traverse.Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?Line 1: Three space-separated integers, respectively: N, M, and XLines 2..M+1: Line i+1 describes road i with three space-separated integers: A i, B i, and T i. The described road runs from farm A i to farm B i, requiring T i time units to traverse.OutputLine 1: One integer: the maximum of time any one cow must walk.Sample Input4 8 21 2 41 3 21 4 72 1 12 3 53 1 23 4 44 2 3Sample Output10HintCow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.USACO 2007 February Silver#include <iostream>using namespace std;const int INF = 1 << 28;int adj[1001][1001], adjw[1001][1001], na[1001];int n, m, x;//heap sink,swim,getmin,insert参数均为外部编号,wt为其权值int heap[100001], id[100001], hsize;int *key;void init(int s, int *wt) {int i;hsize = s;key = wt;for (i=1; i<=hsize; i++) {heap[i] = i;id[i] = i;}}void swim(int u) {int p = id[u], q = p >> 1, ku = key[u];while (q && ku < key[heap[q]]) {id[heap[q]] = p;heap[p] = heap[q];p = q;q = p >> 1;}id[u] = p;heap[p] = u;}void sink(int u) {int p = id[u],q = p << 1, ku = key[u];while (q <= hsize) {if (q < hsize && key[heap[q+1]] < key[heap[q]]) q++;if (key[heap[q]] >= ku) break;id[heap[q]] = p;heap[p] = heap[q];p = q;q = p << 1;}id[u] = p;heap[p] = u;}int getmin() {int ret = heap[1];id[ret] = -1;id[heap[hsize]] = 1;heap[1] = heap[hsize];hsize--;sink(heap[1]);return ret;}void insert(int u) {heap[++hsize] = u;id[u] = hsize;swim(u);}void build() {int i;for (i=hsize/2; i>0; i--) sink(heap[i]); }bool isEmpty() {return hsize == 0;}int dijkstraHeap(int beg, int end=-1) {int i, j, k, u, v, w;int dist[1001], chk[1001];for (i=1; i<=n; i++) {dist[i] = INF;chk[i] = 0;}init(n, dist);dist[beg] = 0; swim(beg);while (!isEmpty()) {u = getmin();if (u == end) break;chk[u] = 1;for (i=0; i<na[u]; i++) {v = adj[u][i];w = adjw[u][i];if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w;swim(v);}}}if (end == -1) return dist[n];return dist[end];}int main() {int i, j, k, u, v, w;int val[1001];scanf("%d%d%d", &n, &m, &x);for (i=0; i<m; i++) {scanf("%d%d%d", &u, &v, &w);adj[u][na[u]] = v;adjw[u][na[u]] = w;na[u]++;}dijkstraHeap(x);memcpy(val, key, sizeof(val));int ans = 0;for (i=1; i<=n; i++) {int tmp = dijkstraHeap(i,x);if (tmp+val[i] > ans) ans = tmp + val[i]; }printf("%d\n", ans);return 0;}。
2023年福建省第三届大学生程序设计竞赛题目

Problem A Solve equationAccept: 111 Submit: 229Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionYou are given two positive integers A and B in Base C. For the equation:A=k*B+dWe know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:(1) A=0*B+123(2) A=1*B+23As we want to maximize k, we finally get one solution: (1, 23)The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.InputThe first line of the input contains an integer T (T≤10), indicating the number of test cases.Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.OutputFor each test case, output the solution “(k,d)” to the equation in Base 10. Sample Input32bc 33f 16123 100 101 1 2Sample Output(0,700)(1,23)(1,0)Problem B Bin & Jing in wonderlandAccept: 4 Submit: 28Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionBin has a dream that he and Jing are both in a wonderland full of beautiful gifts. Bin wants to choose some gifts for Jing to get in her good graces.There are N different gifts in the wonderland, with ID from 1 to N, and all kinds of these gifts have infinite duplicates. Each time, Bin shouts loudly, “I love Jing”, and then the wonder land random drop a gift in front of Bin. The dropping probability for gift i (1≤i≤N) is P(i). Of cause, P(1)+P(2)+…+P(N)=1. Bin finds that the gifts with the higher ID are better. Bin shouts k times and selects r best gifts finally.That is, firstly Bin gets k gifts, then sorts all these gifts according to their ID, and picks up the largest r gifts at last. Now, if given the final list of the r largest gifts, can you help Bin find out the probability of the list?InputThe first line of the input contains an integer T (T≤2,000), indicating number of test cases.For each test cast, the first line contains 3 integers N, k and r (1≤N≤20, 1≤k≤52,1≤r≤min(k,25)) as the description above. In the second line, there are N positive float numbers indicates the probability of each gift. There are at most 3 digits after the decimal point. The third line has r integers ranging from 1 to N indicates the finally list of the r best gifts’ ID.OutputFor each case, output a float number with 6 digits after the decimal points, which indicates the probability of the final list.Sample Input42 3 30.3 0.71 1 12 3 30.3 0.71 1 22 3 30.3 0.71 2 22 3 30.3 0.72 2 2Sample Output0.0270000.1890000.4410000.343000Problem C Floor problemAccept: 133 Submit: 150Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionIn this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.You are given 3 positive integers n, L and R. Print the result off(n,L)+f(n,L+1)+...+f(n,R), please.InputThe first line of the input contains an integer T (T≤100), indicating the number of test cases.Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000,L≤R). OutputFor each test case, print the result of f(n,L)+f(n,L+1)+...+f(n,R) in a single line. Sample Input31 2 3100 2 100100 3 100Sample Output382332Problem D Digits CountAccept: 11 Submit: 64Time Limit: 10000 mSec Memory Limit : 262144 KB Problem DescriptionGiven N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations:Operation 1: AND opn L RHere opn, L and R are integers.For L≤i≤R, we do A[i]=A[i] AND opn (here "AND" is bitwise operation).Operation 2: OR opn L RHere opn, L and R are integers.For L≤i≤R, we do A[i]=A[i] OR opn (here "OR" is bitwise operation).Operation 3: XOR opn L RHere opn, L and R are integers.For L≤i≤R, we do A[i]=A[i] XOR opn (here "XOR" is bitwise operation).Operation 4: SUM L RWe want to know the result of A[L]+A[L+1]+...+A[R].Now can you solve this easy problem?InputThe first line of the input contains an integer T, indicating the number of test cases. (T≤100)Then T cases, for any case, the first line has two integers n and m (1≤n≤1,000,000, 1≤m≤100,000), indicating the number of elements in A and the number of operations.Then one line follows n integers A[0], A[1], ..., A[n-1] (0≤A[i]<16,0≤i<n).Then m lines, each line must be one of the 4 operations above. (0≤opn≤15) OutputFor each test case and for each "SUM" operation, please output the result with a single line.Sample Input14 41 2 4 7SUM 0 2XOR 5 0 0OR 6 0 3SUM 0 2Sample Output718HintA = [1 2 4 7]SUM 0 2, result=1+2+4=7;XOR 5 0 0, A=[4 2 4 7];OR 6 0 3, A=[6 6 6 7];SUM 0 2, result=6+6+6=18.Problem E How many tuplesAccept: 0 Submit: 0Time Limit: 10000 mSec Memory Limit : 65536 KB Problem DescriptionGiven m positive integer a[1],a[2]…a[m]. We run the following program (in C++):const int MAXN = 20;int a[MAXN], m;int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}long long cnt = 0;void gao(int cur, int g) {if (cur > m) {if (g == 1)++cnt;return;}for (int i = 1; i <= a[cur]; ++i)gao(cur + 1, g < 0 ? i : gcd(g, i));}int main() {scanf("%d", &m);for (int i = 1; i <= m; ++i)scanf("%d", a + i);gao(1, -1);cout << cnt << endl;return 0;}Here gcd is the Greatest Common Divisor, Obviously, the program above is to find the number of tuples (b[1], b[2], …, b[m]) such that:(1) gcd(b[1], b[2], …, b[m])=1. (Here we define gcd(num)=num, that is: gcd(9)=9, gcd(2)=2)(2) 1≤b[i]≤a[i]. (1≤i≤m, b[i] is an integer)Now in this problem, the m and a[i] may be very large! So could you write one efficient program to find the answer? The answer may be too large. So you can just output the answer Mod 1,000,000,007.InputThe first line of the input contains an integer T (T≤10,000), indicating the number of test cases.Then T cases, for any case, only two lines.The first line is one integer m(1≤m≤20).The second line has m integers indicate a[1], a[2], …, a[m] (1≤a[i]≤100,000,000,1≤i≤m).The answer may be too large. So you can just output the answer Mod 1,000,000,007. OutputFor each test case, print a line containing the answer Mod 1,000,000,007. Sample Input325 5210000 987321234 5678Sample Output19600261564261566Problem F Hua Rong DaoAccept: 22 Submit: 66Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionCao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one 1*2grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is empty.There is only one Cao Cao. The number of Cross general, vertical general, and soldier is not fixed. How many ways can all the people stand?InputThere is a single integer T (T≤4) in the first line of the test data indicating that there are T test cases.Then for each case, only one integer N (1≤N≤4) in a single line indicates the length of Hua Rong Dao.OutputFor each test case, print the number of ways all the people can stand in a single line. Sample Input212Sample Output18HintHere are 2 possible ways for the Hua Rong Dao 2*4.Problem H Mountain NumberAccept: 2 Submit: 7Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionOne integer number x is called "Mountain Number" if:(1) x>0 and x is an integer;(2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is positive). Any a[2i+1] is larger or equal to a[2i] and a[2i+2](if exists).For example, 111, 132, 893, 7 are "Mountain Number" while 123, 10, 76889 are not "Mountain Number".Now you are given L and R, how many "Mountain Number" can be found between L and R (inclusive) ?InputThe first line of the input contains an integer T (T≤100), indicating the number of t est cases.Then T cases, for any case, only two integers L and R (1≤L≤R≤1,000,000,000). OutputFor each test case, output the number of "Mountain Number" between L and R in a single line.Sample Input31 101 1001 1000Sample Output954384Problem I StarAccept: 78 Submit: 320Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionOverpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.InputThe first l ine of the input contains an integer T (T≤10), indicating the number of test cases.For each test case:The first line contains one integer n (1≤n≤100), the number of stars.The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicat e the points, all the points are distinct.OutputFor each test case, output an integer indicating the total number of different acute triangles.Sample Input130 010 05 1000Sample Output1Problem J Min NumberAccept: 85 Submit: 261Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionNow you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| mea ns the length of n’s 10-base notation. Then we can swap n[i] and n[j].For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?Please note that in this problem, leading zero is not allowed!InputThe first line of the input contains an integer T (T≤100), indicating the number of test cases.Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.OutputFor each test case, output the minimum number we can get after no more than M operations.Sample Input39012 09012 19012 2Sample Output901210921029Problem K TicketsAccept: 14 Submit: 50Time Limit: 3000 mSec Memory Limit : 32768 KB Problem DescriptionYou have won a collection of tickets on luxury cruisers. Each ticket can be used only once, but can be used in either direction between the 2 different cities printed on the ticket. Your prize gives you free airfare to any city to start your cruising, and free airfare back home from wherever you finish your cruising.You love to sail and don't want to waste any of your free tickets. How many additional tickets would you have to buy so that your cruise can use all of your tickets?Now giving the free tickets you have won. Please compute the smallest number of additional tickets that can be purchased to allow you to use all of your free tickets. InputThere is one integer T (T≤100) in the first line of the input.Then T cases, for any case, the first line contains 2 integers n, m (1≤n, m≤100,000). n indicates the identifier of the cities are between 1 and n, inclusive. m indicates the tickets you have won.Then following m lines, each line contains two integers u and v (1≤u, v≤n), indicates the 2 cities printed on your tickets, respectively.OutputFor each test case, output an integer in a single line, indicates the smallest number of additional tickets you need to buy.Sample Input35 31 31 24 56 51 31 21 61 51 43 21 21 2Sample Output12。
第三届ACM校赛题目

WBC白细胞 4.0-10.0*109/L 过高:多为炎症,显著异常增高还可能是白血病或恶性肿瘤
RBC红细胞 3.5-5.5*1012/L 过低:贫血;
过高:红细胞增多症、高粘血症
HGB血红蛋白男:120-160g/L
女:110-150g/L
过低:贫血;
过高:红细胞增多症
HCT红细胞比积男:42-48%
女:36-40%
过低:贫血;
过高:红细胞增多症
血常规
PLT血小板计数100-300*109/L 用于检测凝血系统功能,过低见于再生障碍性贫血、白血病
现在给你一张化验单(至于它是谁的,你就别问了),让你判断其所有指标是否正常,如果不正常,统计有几项不正常。
化验单上的值必须严格落在正常参考值范围内,才算是正常。
正常参考值范围包括边界,即落在边界上也算正常。
输入:
输入第一行包含一个整数k(0<k<100),表示有k组测试数据。
接下来k行,每行包含一组测试数据。
每组测试数据第一项是一个英文单词(male:表示男,或female:表示女),表示受测者的性别;第二项是白细胞的值(以109/L为单位);第三项是红细胞的值(以1012/L为单位);第四项是血红蛋白的值(以g/L。
acm选拔试题及答案

acm选拔试题及答案# acm选拔试题及答案1. 问题描述:编写一个程序,计算给定整数序列中,连续子序列的最大和。
2. 输入格式:第一行包含一个整数 \( n \),表示序列的长度。
第二行包含 \( n \) 个整数,表示序列中的元素。
3. 输出格式:输出一个整数,表示连续子序列的最大和。
4. 示例:输入:```51 -234 -1```输出:```6```5. 问题分析:这个问题可以通过动态规划的方法来解决。
定义一个数组 `dp[i]` 来表示以第 `i` 个元素结尾的连续子序列的最大和。
6. 算法逻辑:- 初始化 `dp[0]` 为序列的第一个元素。
- 对于每个 `i`(从 1 到 `n-1`),`dp[i]` 可以通过 `dp[i-1] + nums[i]` 来更新,如果 `dp[i-1]` 是负数,则 `dp[i]` 应该等于`nums[i]`。
- 遍历序列,更新 `dp` 数组,同时记录最大和。
7. 代码实现:```pythondef max_subarray_sum(nums):n = len(nums)max_sum = nums[0]current_sum = nums[0]for i in range(1, n):current_sum = max(nums[i], current_sum + nums[i]) max_sum = max(max_sum, current_sum)return max_sum```8. 测试用例:- 输入:`[-2, 1, -3, 4, -1, 2, 1, -5, 4]`- 输出:`6`9. 答案解析:- 该测试用例中,连续子序列 `[4, -1, 2, 1]` 的和为 `6`,是所有可能子序列中的最大值。
10. 注意事项:- 考虑边界条件,如序列中所有元素都是负数的情况。
- 优化算法以处理大数据量的情况。
11. 附加说明:- 该问题也可以通过分治法或贪心算法来解决,但动态规划提供了一个更简洁且易于理解的解决方案。
ACM程序设计竞赛例题[1]
![ACM程序设计竞赛例题[1]](https://img.taocdn.com/s3/m/4595c6dd7cd184254a353550.png)
备战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比较{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) //且价值大于max max=value; //替换max}void readdata(){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程序设计竞赛例题[1]
![ACM程序设计竞赛例题[1]](https://img.taocdn.com/s3/m/8e8360ed84868762cbaed565.png)
A C M程序设计竞赛例题[1]-CAL-FENGHAI.-(YICAI)-Company One1备战ACM资料习题1.0-1背包问题在0 / 1背包问题中,需对容量为c 的背包进行装载。
从n 个物品中选取装入背包的物品,每件物品i 的重量为wi ,价值为pi 。
对于可行的背包装载,背包中物品的总重量不能超过背包的容量,最佳装载是指所装入的物品价值最高。
程序如下:#include <>void readdata();void search(int);void checkmax();void printresult();int c=35, n=10; ");printf("\n");}printf("\n");}6.素数环问题把从1到20这20个数摆成一个环,要求相邻的两个数的和是一个素数。
分析:用回溯算法,考察所有可能的排列。
程序如下:#include <>#include <>void search(int);void init(); 表示空格;’X’表示墙。
程序如下:#include <>#include <>void search(int,int);int canplace(int,int);void readdata(); Floodfill给一个20×20的迷宫和一个起点坐标,用广度优先搜索填充所有的可到达的格子。
提示:参考第2题。
2. 电子老鼠闯迷宫如下图12×12方格图,找出一条自入口(2,9)到出口(11,8)的最短路本题给出完整的程序和一组测试数据。
状态:老鼠所在的行、列。
程序如下:#include<>void readdata();a[i][j]=0; ....注:测试数据可在运行时粘贴上去(点击窗口最左上角按钮,在菜单中选则“编辑”/“粘贴”即可)。
ACM程序设计试题及参考答案

ACM程序设计试题及参考答案猪的安家Andy和Mary养了很多猪。
他们想要给猪安家。
但是Andy没有足够的猪圈,很多猪只能够在一个猪圈安家。
举个例子,假如有16头猪,Andy建了3个猪圈,为了保证公平,剩下1头猪就没有地方安家了。
Mary生气了,骂Andy没有脑子,并让他重新建立猪圈。
这回Andy建造了5个猪圈,但是仍然有1头猪没有地方去,然后Andy又建造了7个猪圈,但是还有2头没有地方去。
Andy都快疯了。
你对这个事情感兴趣起来,你想通过Andy建造猪圈的过程,知道Andy家至少养了多少头猪。
输入输入包含多组测试数据。
每组数据第一行包含一个整数n (n <= 10) – Andy 建立猪圈的次数,解下来n行,每行两个整数ai, bi( bi <= ai <= 1000), 表示Andy建立了ai个猪圈,有bi头猪没有去处。
你可以假定(ai, aj) = 1.输出输出包含一个正整数,即为Andy家至少养猪的数目。
样例输入33 15 17 2样例输出16答案:// 猪的安家.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream.h"void main(){int n;int s[10][2];bool r[10];char ch;cout<<"请输入次数:"<<endl;cin>>n;for (int i=0;i<n;i++){cout<<"请输入第"<<i+1<<"次的猪圈个数和剩下的猪:,用--分开,"<<endl;cin>>s[i][0]>>ch>>ch>>s[i][1];}for (i=0;i<10;i++)r[i]=true;for (int sum=1;;sum++){for (i=0;i<n;i++)r[i]=(sum%s[i][0]==s[i][1]);for (i=0;i<n;i++){if (r[i]==0)break;}if (i==n)break;}cout<<"猪至少有"<<sum<<"只。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
计算机工程学院第三届ACM程序设计大赛试题Problem A BridgeDescriptionn people wish to cross a bridge at night. A group of at most two people may cross at any time, and each group must have a flashlight. Only one flashlight is available among the n people, so some sort of shuttle arrangement must be arranged in order to return the flashlight so that more people may cross.Each person has a different crossing speed; the speed of a group is determined by the speed of the slower member. Your job is to determine a strategy that gets all n people across the bridge in the minimum time.InputThe first line of input contains n, followed by n lines giving the crossing times for each of the people. There are not more than 1000 people and nobody takes more than 100 seconds to cross the bridge. OutputThe first line of output must contain the total number of seconds required for all n people to cross the bridge. The following lines give a strategy for achieving this time. Each line contains either one or two integers, indicating which person or people form the next group to cross. (Each person is indicated by the crossing time specified in the input. Although many people may have the same crossing time the ambiguity is of no consequence.) Note that the crossings alternate directions, as it is necessary to return the flashlight so that more may cross. If more than one strategy yields the minimal time, any one will do.Sample Input(Input file: pa.txt)412510Sample Output171 215 1021 2Problem B LottoDescriptionIn the German Lotto you have to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chance of winning - is to select a subset S containing k (k > 6) of these 49 numbers, and then play several games with choosing numbers only from S. For example, for k=8 and S = {1,2,3,5,8,13,21,34} there are 28 possible games: [1,2,3,5,8,13], [1,2,3,5,8,21],[1,2,3,5,8,34], [1,2,3,5,13,21], ... [3,5,8,13,21,34].Your job is to write a program that reads in the number k and the set S and then prints all possible games choosing numbers only from S.InputThe input will contain one or more test cases. Each test case consists of one line containing several integers separated from each other by spaces. The first integer on the line will be the number k (6 < k < 13). Then k integers, specifying the set S, will follow in ascending order. Input will be terminated by a value of zero (0) for k.OutputFor each test case, print all possible games, each game on one line. The numbers of each game have to be sorted in ascending order and separated from each other by exactly one space. The games themselves have to be sorted lexicographically, that means sorted by the lowest number first, then by the second lowest and so on, as demonstrated in the sample output below. The test cases have to be separated from each other by exactly one blank line. Do not put a blank line after the last test case.Sample Input(Input file: pb.txt)7 1 2 3 4 5 6 78 1 2 3 5 8 13 21 34Sample Output1 2 3 4 5 61 2 3 4 5 71 2 3 4 6 71 2 3 5 6 71 2 4 5 6 71 3 4 5 6 72 3 4 5 6 71 2 3 5 8 131 2 3 5 8 211 2 3 5 8 341 2 3 8 13 211 2 3 8 13 341 2 3 8 21 341 2 3 13 21 341 2 5 8 13 211 2 5 8 13 341 2 5 8 21 341 2 5 13 21 341 2 8 13 21 341 3 5 8 13 211 3 5 8 13 341 3 5 8 21 341 3 5 13 21 341 3 8 13 21 341 5 8 13 21 342 3 5 8 13 212 3 5 8 13 342 3 5 8 21 342 3 5 13 21 342 3 8 13 21 342 5 8 13 21 343 5 8 13 21 34Problem C EncryptChip and Dale have devised an encryption method to hide their (written) text messages. They first agree secretly on two numbers that will be used as the number of rows (R) and columns (C) in a matrix. The sender encodes an intermediate format using the following rules:1. The text is formed with uppercase letters [A-Z] and <space>.2. Each text character will be represented by decimal values as follows:<space> = 0, A = 1, B = 2, C = 3, ..., Y = 25, Z = 26The sender enters the 5 digit binary representation of the characters' values in a spiral pattern along the matrix as shown below. The matrix is padded out with zeroes (0) to fill the matrix completely. For example, if the text to encode is: "ACM" and R=4 and C=4, the matrix would be filled in as follows:A = 00001, C = 00011, M = 01101 (one extra 0)The bits in the matrix are then concatenated together in row major order and sent to the receiver. The example above would be encoded as: 0000110100101100Inputspace, and a string of binary digits that represents the contents of the matrix (R * C binary digits). The binary digits are in row major order.OutputFor each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, and the decoded text message. You should throw away any trailing spaces and/or partial characters found while decoding.Sample Input(Input file: pc.txt)24 4 ACM5 2 HISample Output1 00001101001011002 0110000010Problem D ConnectionThere are N cities in the country and M bidirectional roads between the cities. The government wants to build some new roads such that for any pair of cities there is at least one path between them. Now you have to find out the minimal amount of roads that have to build.InputThe input may contain multiple test cases.For each test case, the first line is two integers N (1<=N<=100) and M (1<=M<=N*N/2),indicating the number of cities and the number of roads. Then the next M lines each contain two integers x and y (0<=x,y<n), meaning that there is a road between cities x and cities y.N=M=0 indicates the end of input.OutputFor each test case, print the answer in a single li ne.Sample Input(Input file: pd.txt)5 20 12 3Sample Output2Problem E GridlandBackgroundFor years, computer scientists have been trying to find efficient solutions to different computing problems. For some of them efficient algorithms are already available, these are the "easy" problems like sorting, evaluating a polynomial or finding the shortest path in a graph. For the "hard" ones only exponential-time algorithms are known. The traveling-salesman problem belongs to this latter group. Given a set of N towns and roads between these towns, the problem is to compute the shortest path allowing a salesman to visit each of the towns once and only once and return to the starting point.ProblemThe president of Gridland has hired you to design a program that calculates the length of the shortest traveling-salesman tour for the towns in the country. In Gridland, there is one town at each of the points of a rectangular grid. Roads run from every town in the directions North, Northwest, West, Southwest, South, Southeast, East, and Northeast, provided that there is a neighbouring town in that direction. The distance between neighbouring towns in directions North�CSouth or East�CWest is 1 unit. The length of the roads is measured by the Euclidean distance. For example, Figure 7 shows 2 �� 3-Gridland, i.e., a rectangular grid of dimensions 2 by 3. In 2 �� 3-Gridland, the shortest tour has length 6.Figure 7: A traveling-salesman tour in 2 �� 3-Gridland.InputThe first line contains the number of scenarios.For each scenario, the grid dimensions m and n will be given as two integer numbers in a single line, separated by a single blank, satisfying 1 < m < 50 and 1 < n < 50.OutputThe output for each scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. In the next line, print the length of the shortest traveling-salesman tour rounded to two decimal digits. The output for every scenario ends with a blank line.Sample Input(Input file: pe.txt)2Sample OutputScenario #1:4.00Scenario #2:6.00Problem F Digital RootsBackgroundThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.InputThe input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.OutputFor each integer in the input, output its digital root on a separate line of the output.Sample input(Input file: pf.txt)2439Sample Output63Problem G Counting NumbersStarting from a positive integer n (1<=n<=2001).On the left of the integer n ,you can place another integer m to form a new integer mn , where m must be less then or equal to half of the integer n ,If there is an integer k less then or equal to half of m, you can place integer k on the left of mn ,to form a new integer kmn,…,and so on .For Examole ,you can place 12 on the left of 30 to Form an integer 1230,and you can place 6 to the left of 1230 to form an integer 61230,…,and so onFor example , start from n=8.you can place integer 1,2,3and 4 to the left of 8 to get the integers 18,28,38,48.For number 18,you can not form a new integer using the procedure described as above.For number28 and 38,you can form new integers 128 and 138.For number 48 ,you can place 1 and 2 on the left of 48 to get new integers 148 and 248.For number 248,you can place 1 on the left of it to get a new integer 1248.In total, you can have the following 10 integers(includeing the integer you start with)8182838481281381482481248Give an integer n ,find the number of integers you can get using the procedure described above.InputAn integer nOutputAn integer witch represents the number of integer you can get.Sample input: (Input file: pg.txt)8Sample Output:10Problem H Buy Low, Buy LowerThe advice to "buy low" is half the formula to success in the stock market. But to be considered a great investor you must also follow this problems' advice:"Buy low, buy lower"That is, each time you buy a stock, you must purchase more at a lower price than the previous time you bought it. The more times you buy at a lower price than before, the better! Your goal is to see how many times you can continue purchasing at ever lower prices.You will be given the daily selling prices of a stock over a period of time. You can choose to buy stock on any of the days. Each time you choose to buy, the price must be lower than the previous time you bought stock. Write a program which identifies which days you should buy stock in order to maximize the number of times you buy.By way of example, suppose on successive days stock is selling like this:Day 1 2 3 4 5 6 7 8 9 10 11 12Price 68 69 54 64 68 64 70 67 78 62 98 87In the example above, the best investor (by this problem, anyway) can buy at most four times if they purchase at a lower price each time. One four day sequence (there might be others) of acceptable buys is:Day 2 5 6 10Price 69 68 64 62PROGRAM NAME: buylowInputLine 1: N (1 <= N <= 5000), the number of days for which stock prices are available.Line 2..etc: A series of N positive space-separated integers (which may require more than one line of data) that tell the price for that day. The integers will fit into 32 bits quite nicely.Outputthe length of the longest sequence of decreasing pricesSample input: (Input file: ph.txt)1268 69 54 64 68 64 70 67 78 62 98 87Sample Output:4注意事项:1、数据从文件输入,标准输出,注意输入文件名题中已经给出。