历届程序设计acm试题

合集下载

山东科技大学第二届ACM程序设计大赛试题

山东科技大学第二届ACM程序设计大赛试题

山东科技大学第二届ACM程序设计大赛试题册试题共14页,题目共计12道山东科技大学第二届ACM 程序设计大赛试题册Problem A 简单计算Description给出n 个十进制的数,找出这n 个数的二进制表示中1的个数最少的数。

Input输入的第一行为一个正整数T (1≤T ≤20),代表测试数据组数。

对于每组测试数据,输入的第一行为一个正整数n (1≤n ≤10000),第二行为n个正整数A 1、A 2、…、A n (1≤A i ≤109),每个数之间以空格分隔。

Output每组数据输出一行,先输出数据组数,再输出二进制中含1最少的数,如果存在多个数符合条件,输出最小的那个。

具体输出格式见样例输出。

Sample Input Sample Output山东科技大学第二届ACM 程序设计大赛试题册Problem B 关键字搜索Description我们的新网站具有了全新的搜索功能,使用了2个通配符“*”和“?”,其中“*”表示0或者多个小写字母,“?”代表1个字母。

当我们输入一个关键字的时候,我们在不确定的地方就使用通配符。

我们在数据库里面有多条记录,每条记录都是由小写字母组成,现在给出一个关键字,你能告诉我数据库里面有多少条与关键字相匹配的记录吗?例如: 如果关键字是j*y*m*y?,那么jiyanmoyu ,jyanmoyu ,jymyu 都是相匹配的记录。

Input第一行输入一个T (T ≤20),表示有T 组测试数据。

对于每组测试数据,第一行是输入的关键字,接下是数据库里面的所有记录的条数n ,1≤n ≤10000,每条记录的长度不超过50个小写字母。

Output对于每组测试数据,输出与关键字相匹配的总记录条数,占一行。

Sample Input Sample Output山东科技大学第二届ACM 程序设计大赛试题册Problem C 正方形Description在二维坐标轴内给出四个点,这四个点能否构成一个正方形。

计算机acm试题及答案

计算机acm试题及答案

计算机acm试题及答案一、选择题1. 在计算机科学中,ACM代表什么?A. 人工智能与机器学习B. 计算机辅助制造C. 计算机辅助设计D. 国际计算机学会答案:D2. 下列哪个不是计算机程序设计语言?A. PythonB. JavaC. C++D. HTML答案:D3. 在计算机系统中,CPU代表什么?A. 中央处理单元B. 计算机辅助设计C. 计算机辅助制造D. 计算机辅助教学答案:A二、填空题1. 计算机的内存分为__________和__________。

答案:RAM;ROM2. 在编程中,__________是一种用于存储和操作数据的数据结构。

答案:数组3. 计算机病毒是一种__________,它能够自我复制并传播到其他计算机系统。

答案:恶意软件三、简答题1. 请简述计算机操作系统的主要功能。

答案:计算机操作系统的主要功能包括管理计算机硬件资源,提供用户界面,运行应用程序,以及控制其他系统软件和应用软件的运行。

2. 什么是云计算,它与传统的本地计算有何不同?答案:云计算是一种通过互联网提供计算资源(如服务器、存储、数据库、网络、软件等)的服务模式。

与传统的本地计算相比,云计算允许用户按需获取资源,无需购买和维护物理硬件,具有更高的灵活性和可扩展性。

四、编程题1. 编写一个程序,计算并输出从1到100(包括1和100)之间所有偶数的和。

答案:```pythonsum = 0for i in range(1, 101):if i % 2 == 0:sum += iprint(sum)```2. 给定一个字符串,编写一个函数,将字符串中的所有字符按ASCII 码值排序并返回。

答案:```pythondef sort_string(s):return ''.join(sorted(s))```五、论述题1. 论述计算机硬件和软件之间的关系及其对计算机系统性能的影响。

答案:计算机硬件是计算机系统的物质基础,包括CPU、内存、硬盘等,而软件则是运行在硬件上的程序和数据。

历届程序设计acm试题

历届程序设计acm试题

搜集的南开大学的ACM试题与你共享[A]南开大学Onlinejudge 在线判题系统A.Lucy的新难题时间限制:2秒内存限制:32000KB不知不觉,南开大学第三届“我为程序狂”又要拉开帷幕了。

这天,Lucy也来到南开大学ACM协会,与大家共同欢庆NKPC的三周岁的日子。

谈笑间,ACM协会的主席拿了圆形的生日蛋糕。

大伙开心地唱完了生日歌,一起吹灭了蜡烛。

要分蛋糕了,大家都很兴奋。

本着公平的原则,每位到场的人员都要在蛋糕上切一刀。

ACM协会的主席事先知道有n位朋友会参与这个欢庆宴会。

为了方便大家切蛋糕,主席在订蛋糕的时候就嘱咐在蛋糕的边缘布置上2n朵小花。

每个人切蛋糕都会从蛋糕的边缘的一朵小花笔直地切到蛋糕的另一端的小花,来表达自己对NKPC的祝福。

为了尊重其他同学,每个人在切蛋糕一定不会和蛋糕上已有的切痕相交,也不会从别人已切过的小花作为切蛋糕的起点或终点。

同时,每位同学在切蛋糕的时候,都要保证后面所有的同学都能够按照上述的规则切蛋糕。

这样,蛋糕上就留下n条切痕。

Lucy眨巴眨巴眼睛,问,要是不考虑切蛋糕的先后顺序和谁切的哪一刀,这蛋糕切完了共有多少种切法呢?大家听了呵呵一笑,说,那就把这个问题留给NKPC3,作为《Lucy的新难题》吧。

相信聪明的你,一定能够帮Lucy解答她的难题的,对吗?输入包括多组测试数据,你应当处理到输入结束为止。

每组输入数据中,都只有一行,仅包含一个正整数n,且0<n≤30。

对于每组输入数据,输出两行。

对于第i组输入数据,输出的第一行为”Case i:”,输出的第二行为切蛋糕的方法数。

[B]南开大学Onlinejudge 在线判题系统B.保龄球时间限制:2秒内存限制:32000KB南开大学ACM协会的一个元老毕业后,开了家保龄球馆。

他需要为他的保龄球馆的计算机写一个记分的程序。

一局(GAME)保龄球分为10格,每格里有两次投球机会,如在第一次投球时没能全中,就有需要投第二球。

大学ACM考试题目及作业答案整理

大学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个人,以此类推。

acm竞赛试题及答案

acm竞赛试题及答案

acm竞赛试题及答案ACM竞赛试题及答案1. 问题描述:给定一个整数数组,找出数组中没有出现的最小的正整数。

2. 输入格式:第一行包含一个整数n,表示数组的长度。

第二行包含n个整数,表示数组的元素。

3. 输出格式:输出一个整数,表示数组中没有出现的最小的正整数。

4. 样例输入:53 4 1 2 55. 样例输出:66. 问题分析:首先,我们需要理解题目要求我们找出数组中缺失的最小正整数。

这意味着我们需要检查数组中的每个元素,并确定最小的正整数是否在数组中。

7. 算法描述:- 遍历数组,使用一个哈希集合记录出现的数字。

- 从1开始,检查每个正整数是否在哈希集合中,直到找到不在集合中的最小正整数。

8. 代码实现:```pythondef find_missing_positive(nums):seen = set()for num in nums:if num <= 0:continuewhile num in seen or num > len(nums):num += 1seen.add(num)return min(set(range(1, len(nums) + 1)) - seen)```9. 测试用例:- 输入:[3, 4, -1, 1]- 输出:210. 答案解析:在给定的测试用例中,数组[3, 4, -1, 1]中没有出现的最小正整数是2。

这是因为-1不是正整数,所以可以忽略。

数组中已经出现了1和3,所以下一个最小的正整数就是2。

11. 注意事项:- 确保数组中的元素是整数。

- 考虑数组中可能包含0或负数的情况。

- 算法的时间复杂度应尽可能低。

12. 扩展思考:- 如果数组非常大,如何优化算法?- 如果数组中的元素可以是浮点数,算法应该如何修改?13. 参考答案:- 针对大数组,可以考虑使用更高效的数据结构,如平衡二叉搜索树。

- 如果元素是浮点数,需要先将其转换为整数,然后再进行处理。

acm大赛试题及答案

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试题及答案python

acm试题及答案python

acm试题及答案pythonACM试题及答案(Python)1. 问题描述:给定一个整数数组,请编写一个Python函数,找出数组中第二大的数。

2. 输入格式:一个包含整数的列表。

3. 输出格式:一个整数,表示数组中第二大的数。

4. 示例:- 输入:[10, 5, 8, 20, 15]- 输出:155. 答案:```pythondef find_second_max(nums):first_max = float('-inf')second_max = float('-inf')for num in nums:if num > first_max:second_max = first_maxfirst_max = numelif num > second_max and num != first_max:second_max = numreturn second_max if second_max != float('-inf') else None# 示例测试nums = [10, 5, 8, 20, 15]print(find_second_max(nums)) # 输出应为15```6. 分析:此题要求找出数组中第二大的数。

我们可以通过遍历数组,使用两个变量分别记录当前找到的最大值和第二大值。

在遍历过程中,如果当前元素比第一大的元素大,则更新第二大的元素为当前第一大的元素,并将当前元素设为第一大的元素。

如果当前元素小于第一大的元素但大于第二大的元素,则更新第二大的元素。

最后返回第二大的元素。

7. 注意:如果数组中只有一个元素或所有元素都相等,则返回`None`。

第三届ACM程序设计大赛试题new

第三届ACM程序设计大赛试题new

计算机工程学院第三届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、数据从文件输入,标准输出,注意输入文件名题中已经给出。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

搜集的南开大学的ACM试题与你共享[A]南开大学Onlinejudge 在线判题系统A.Lucy的新难题时间限制:2秒内存限制:32000KB不知不觉,南开大学第三届“我为程序狂”又要拉开帷幕了。

这天,Lucy也来到南开大学ACM协会,与大家共同欢庆NKPC的三周岁的日子。

谈笑间,ACM协会的主席拿了圆形的生日蛋糕。

大伙开心地唱完了生日歌,一起吹灭了蜡烛。

要分蛋糕了,大家都很兴奋。

本着公平的原则,每位到场的人员都要在蛋糕上切一刀。

ACM协会的主席事先知道有n位朋友会参与这个欢庆宴会。

为了方便大家切蛋糕,主席在订蛋糕的时候就嘱咐在蛋糕的边缘布置上2n朵小花。

每个人切蛋糕都会从蛋糕的边缘的一朵小花笔直地切到蛋糕的另一端的小花,来表达自己对NKPC的祝福。

为了尊重其他同学,每个人在切蛋糕一定不会和蛋糕上已有的切痕相交,也不会从别人已切过的小花作为切蛋糕的起点或终点。

同时,每位同学在切蛋糕的时候,都要保证后面所有的同学都能够按照上述的规则切蛋糕。

这样,蛋糕上就留下n条切痕。

Lucy眨巴眨巴眼睛,问,要是不考虑切蛋糕的先后顺序和谁切的哪一刀,这蛋糕切完了共有多少种切法呢?大家听了呵呵一笑,说,那就把这个问题留给NKPC3,作为《Lucy的新难题》吧。

相信聪明的你,一定能够帮Lucy解答她的难题的,对吗?输入包括多组测试数据,你应当处理到输入结束为止。

每组输入数据中,都只有一行,仅包含一个正整数n,且0<n≤30。

对于每组输入数据,输出两行。

对于第i组输入数据,输出的第一行为”Case i:”,输出的第二行为切蛋糕的方法数。

[B]南开大学Onlinejudge 在线判题系统B.保龄球时间限制:2秒内存限制:32000KB南开大学ACM协会的一个元老毕业后,开了家保龄球馆。

他需要为他的保龄球馆的计算机写一个记分的程序。

一局(GAME)保龄球分为10格,每格里有两次投球机会,如在第一次投球时没能全中,就有需要投第二球。

每一格可能出现三种情况:1.失球(MISS)无论何种情况,在一格的两次投球时,未能击倒10个瓶,此格的分数为击倒的瓶数。

如果一次击球中未击倒一个瓶,则用一个’-’标记。

2.补中(SPARE)要一次击倒十个瓶子并非那么容易的!如果在第一次掷球后,你还有一次机会来击倒该格第一球所留下的情致。

当第二次投球击倒该格第一球余下的全部瓶子,称为补中,用一个‘/’符号表示。

补中的记分是10分加上下一次投球击倒的瓶数。

3.全中(STRIKE)当每一格的第一次投球击倒全部竖立的十个瓶时,称为全中,用一个(×)符号表示。

全中的记分是10分(击倒的瓶)加该球员下两次投球击倒的瓶数。

但在第十格中情况比较特殊:(1)如第二次投球未补中,则第十格得分为第九格得分加上第十格所击倒瓶数。

(2)如第二次投球补中,则追加一次投球机会,第十格得分为第九格得他加上10加上追加一次投球击倒瓶数。

(3)如第一球为全中,则追上加二次投球机会,第十格得分为第九格得分加上10加追加二次投球击倒的瓶数。

因此从第一格到第十格的两次追加投球,都为全中,则为12个全中,得分为满分300分。

每组输入数据中,都只有一行,包含一局的记分符号,相邻的两个符号之间以一个空格隔开。

记分的符号仅包括…-‟(不含对于每组输入数据,输出两行。

对于第i组输入数据,输出的第一行为”Case i:”,输出的第二行为10个整数,表示每格的累计得分。

相邻的两个得分以一个空格隔开。

[C]南开大学Onlinejudge 在线判题系统C.计算机硬件评分系统时间限制:2秒内存限制:32000KB小C听说微软新推出的一款操作系统Windows Vista可以对电脑的配置进行评分,很感兴趣。

由于小C对硬件软件方面都很了解,就通过一系列的市场调查与实践,制作了一款自己的计算机硬件评分系统。

此系统可以对CPU、内存、硬盘、主板、显卡五部分分别进行评分,分数为不超过100的正整数,并以这五个分数中的最低分作为对计算机的总体评分。

同寝室的小D打算最近购置一台新电脑,他请小C给他当参谋,小C就提供了一些当前的CPU、内存、硬盘、主板、显卡五种硬件的品牌、价格以及每个硬件由他所制作的系统所评价出来的分数。

小D准备至多用N元来购买这五种硬件并且他还希望能够得到一台电脑有尽量高的总体评分。

作为寝室长的你主动要写一个程序来帮助小D购买电脑。

表示资料中所提供的这种硬件品种数目M。

下面M行每一行都描述了一个品种的情况,包括两个整数,以空格隔开。

第一个费。

[D]南开大学Onlinejudge 在线判题系统D.朋友们的距离时间限制:2秒内存限制:32000KB要放假了,考完了所有试就等着上火车回家的Butterfly0923 面对着自己心爱的计算机,无聊的逛着我爱南开BBS,眼看着在线好友列表的长度一天天减少。

“来自”一栏中的IP 都还是校内的,大多以10 开头。

Butterfly0923 看到大部分人跟自己同在21 宿,还有15 宿的老乡、13 宿的狐朋狗友们、西区的研究生、12 宿的音乐狂人和8 宿的可爱小女生。

虽然现在大家仅仅相隔几百米,但是很快彼此将远隔万水千山,分散在祖国各地。

如果那时大家一起上线,各地IP 大展览,一定有趣,Butterfly0923 这样想。

不过祖国这么大,不知道大家到底相距多远。

于是Butterfly0923 给所有在线的ID寄语信鸽,询问他/她的家乡与学校之间的距离,他想知道自己的朋友中谁离学校最远。

Butterfly0923 知道自己的家距学校520km,seaeagle 也知道,所以他回信说:我家离学校的距离比你的四倍还多200km。

不过doraemonok 不知道,他比较务实,直接回信说:12km,公交1hour。

迷糊的Butterfly0923 想了想,觉得seaeagle 比较远一点。

但是随着问的人越来越多,问题变得复杂起来。

unusualwater 说:我的距离是你的十三分之一。

aliao 说:我刚问过gnr,你们的旅途合在一起比我少194km。

而gnr 老师的回信说:我的路程正好是你的两倍。

这回,Butterfly0923 算了好大一会,才知道aliao 最远。

Butterfly0923 最后寄语信鸽了爱好编程的你,不过不是问距离,他告诉你他从各个ID 得到的信息,希望你能告诉他最远的地方有多少公里,是谁在那里。

会超过26。

接下来n 行是这n 个在线ID,每行一个。

按照我爱南开BBS 站的规定,ID 由2-12 个英文字母组成,大小写不敏感。

再往下n 行是从各人回信中得到的信息。

方便起见,Butterfly0923 把每条信息写成等式的形式。

等号两边有一些项,每一项都是num*ID 的形式,num 是一个正整数,没有符号,多项之间以加号分隔,最后一项可能是一个常数。

Butterfly0923 自己也可能出现在等式中,注意它不是一个ID ——它太长了。

Butterfly0923 保证在一个等式中不会出现相同的ID,每个人的距离(如果能算得出的话)都是整数。

所有ID 和等式中都不会出现任何前导、后缀以及符号两侧的空格。

如果朋友们给Butterfly0923 的信息不足以确定全部人的距离,就在第二行输出“I‟m not sure about someone‟s distance.”否则第二行输出你计算出的最远距离,第三行输出跟最远距离对应的ID,如果这样的ID 不止一个,按照它们在[E]南开大学Onlinejudge 在线判题系统E.羽毛球轨迹估算时间限制:2秒内存限制:32000KBButterfly0923 喜欢打羽毛球,尽管打得不是很好。

某节杨明老师的羽毛球课上,刚刚打赢了Butterfly0923 的英语系老陈得意的问:“嘿,你知道羽毛球的英文叫做什么?”“嗯……feather ball 吧……”“No, badminton. Do you know why? 这是羽毛球起源的地方,是英国的一个小镇。

”这时杨老师开始讲课:“大家看,羽毛球的飞行轨迹是很有特点的,跟排球篮球足球不一样,羽毛球向上升到最高点,然后几乎垂直落下来。

”Butterfly0923 突然对老陈说:“告诉我初始的速度,高度和角度,我可以告诉你这个球可以飞多远。

”Butterfly0923 的想法是这样的:假定飞行的羽毛球只受到竖直向下的重力G,和与飞行速度v方向相反的空气阻力f,且空气阻力的大小f = k v,其中k 为常数。

设t = 0时球具有初速度v0,速度与水平方向夹角为α,击球高度为y0。

比如,当k = 0.018 时,一只重10g 的羽毛球在离地面2m的地方斜向上与水平方向成45°角,以20m/s 的速度飞出,按照这个模型,经过2.34 秒,羽毛球会落在大约7.74m 远的地方,如下图所示:Butterfly0923 对自己的模型还是很满意的,他正在尝试以不同的角度和力度打一些不同的球,老陈帮忙测量实际距离。

OK,你的任务是计算一下按照这个模型,Butterfly0923 打出去的球会落在离他多远的地方。

每组数据由五个数组成。

第一个数是击球的角度α,杨老师刚刚教了Butterfly0923 如何扣杀,所以α 可能是[-90, 90] 内的任何整数。

接下来是球的初速v0 (m/s)、击球点的高度y0 (m)、球的质量m (kg) 和阻力系数k,都是非负的浮点数,[F]南开大学Onlinejudge 在线判题系统F.找出公共区域时间限制:2秒内存限制:32000KBBetty喜欢玩剪纸。

现在她有两张已经剪好的凸多边形需要粘在一起。

她打算在两张纸的公共区域涂满浆糊,你能计算出这个公共区域有多大吗?输入由两部分组成,每部分的第一行为一个整数介于3和30之间,表示该凸多边形的顶点数目。

下面各行每行包含两个实数,表示凸多边形顶点的横纵坐标。

实数的小数部分为六位且绝对值均小于1000。

顶点顺序按逆时针给出。

请输出一个包含两位小数的实数,表示两个凸多边形的公共区域面积。

[G]南开大学Onlinejudge 在线判题系统G.游戏时间限制:2秒内存限制:32000KB我们在休闲娱乐的时候常常会去玩一些益智小游戏,像扫雷、祖玛、俄罗斯方块之类的恐怕已经没有几个人没玩过了吧。

像这样的游戏能让我们在学习的紧张过后得到一点放松,而且又能活动一下脑子。

现在许多RPG风格的游戏也逐渐的加入一些小游戏的元素来丰富游戏内容,像GBA游戏《被狙击的名侦探》,PC游戏《双星物语》等等就都出现了类似于下面这种样式的小游戏:在一个n×n的方格中,每个方格有一个棋子,棋子或为黑色、或为白色,如图中所示。

现在对棋盘进行操作,每步操作只能选中一个方格,之后这个方格及其上下左右四个相邻的方格(如果有的话)中的棋子均变为相反的颜色。

相关文档
最新文档