安徽ACM省赛试题

合集下载

acm初赛试题及答案

acm初赛试题及答案

acm初赛试题及答案# acm初赛试题及答案1. 问题描述给定一个整数n,求出n以内所有正整数的和。

2. 输入格式输入包含一个整数n(1≤n≤10000)。

3. 输出格式输出一个整数,表示n以内所有正整数的和。

4. 样例输入```100```5. 样例输出```5050```6. 问题分析本题要求计算从1到n的所有正整数的和。

这是一个简单的数学问题,可以通过公式求解。

7. 解题思路使用求和公式:\( \sum_{i=1}^{n} i = \frac{n(n+1)}{2} \)。

8. 算法实现编写一个函数,输入n,输出计算结果。

9. 代码示例```pythondef sum_of_numbers(n):return n * (n + 1) // 2n = int(input())print(sum_of_numbers(n))```10. 注意事项输入的n可能会非常大,需要考虑整数溢出的问题。

11. 测试用例- 输入:1输出:1- 输入:10输出:55- 输入:10000输出:5000500012. 评分标准- 正确性:算法正确,输出结果符合预期。

- 效率:算法执行效率高,能在规定时间内完成计算。

- 代码风格:代码可读性好,注释清晰。

13. 常见错误- 未考虑整数溢出。

- 未正确使用求和公式。

- 代码中存在语法错误。

14. 扩展思考- 如果要求计算从m到n的所有正整数的和,应该如何修改算法? - 如何优化算法以处理更大的输入值?15. 参考答案- 对于扩展思考的第一个问题,可以将求和公式修改为:\( \sum_{i=m}^{n} i = \frac{n(n+1)}{2} - \frac{(m-1)m}{2} \)。

- 对于扩展思考的第二个问题,可以考虑使用更高效的数据结构或者算法来减少计算量。

以上是ACM初赛试题及答案的完整内容。

计算机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 软件大赛之编程大赛比赛注意事项: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试题及答案2

acm试题及答案2

acm试题及答案2ACM试题及答案21. 问题描述:编写一个程序,计算给定整数序列中的最大子段和。

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

第二行包含N个整数,表示序列中的整数。

3. 输出格式:输出一个整数,表示序列中的最大子段和。

4. 样例输入:```51 -2 -34 -1```5. 样例输出:```6```6. 问题分析:该问题可以通过动态规划的方法来解决。

定义一个数组dp,其中dp[i]表示以第i个元素结尾的最大子段和。

状态转移方程为dp[i] = max(dp[i-1] + nums[i], nums[i])。

7. 算法实现:```pythondef maxSubArray(nums):n = len(nums)dp = [0] * ndp[0] = nums[0]max_sum = nums[0]for i in range(1, n):dp[i] = max(dp[i-1] + nums[i], nums[i])max_sum = max(max_sum, dp[i])return max_sum```8. 复杂度分析:时间复杂度为O(n),其中n为序列的长度。

空间复杂度为O(n)。

9. 测试用例:- 输入:`[3, -2, 4]`输出:`5`- 输入:`[-2, 1, -3, 4, -1, 2, 1, -5, 4]`输出:`6`10. 注意事项:- 确保输入的序列长度N大于等于1。

- 序列中的整数可以是负数或正数。

- 输出结果应该是一个整数。

11. 扩展思考:- 如何优化算法以减少空间复杂度?- 如果序列中的整数是浮点数,算法是否仍然有效?12. 参考答案:- 可以通过只使用一个变量来存储最大子段和,以及一个变量来存储当前子段和,从而将空间复杂度优化到O(1)。

- 如果序列中的整数是浮点数,算法仍然有效,但需要注意浮点数运算的精度问题。

ACM程序大赛选拔初赛试题 - 参考答案

ACM程序大赛选拔初赛试题 - 参考答案

《解方程》参考答案:
#include <stdio.h> #include <math.h> void main() {
int a,b,c,d; float x1,x2; scanf("%d %d %d %d",&a,&b,&c,&d); if(a==0) printf("x=%.2f",(float)(d-c)/b); else {
float dr=b*b-4*a*c; c-=d; if(dr>0) {
x1=(-b-sqrt(dr))/(2*a); x2=(-b+sqrt(dr))/(2*a); printf("x1=%.2f x2=%.2f\n",x1,x2); } if(dr==0) { x1=(-b+sqrt(dr))/(2*a); printf("x=%.2f\n",x1); } if(dr<0) printf("no answer\n"); } }
3、计算器 (难度系数:★★★☆☆)
题意:输入一个没有答案的算术式子,用计算机求出输出它的结果。 输入:一个字符串形如“a#b=”(#代表运算符号)。注意:输入的字符串中 a,b 代表的数 都为自然数。而且 a,b 的范围都是从 0 到 999。 输出:字符串对应的算式的答案。答案需保留两位有效数字。若无答案则输出“error” 示例:
输出:第1 行是选出顺序,第2 行是两名幸运儿的开始位置(按升序排列),位置编号之 间用一个空格分开。
示例:
输入(只选一组) 3 5 12
输出(幸运儿的位置)
2 13 241 53 2 4 6 8 10 12 3 7 11 5 19

安徽省青少年信息学奥林匹克竞赛中学组试题

安徽省青少年信息学奥林匹克竞赛中学组试题

2010年安联杯安徽省青少年信息学奥林匹克竞赛中学组试卷AOI 2010比赛时间:2010年4月27日8:00至12:00注意事项1.务必看清题目,严格按照所要求的格式输入、输出。

2.在调试程序时请先使用题目中的示例数据,然后再自行设计多组测试数据进行调试。

3.测试有严格的时间限制,请尽可能优化算法。

4.命名规则:(1)每题都规定了该题的英文名称。

(2)程序文件和数据文件的主文件名都是该题的英文名字。

(3)程序文件扩展名采用语言环境的默认扩展名。

(4)数据文件都是文本文件,输入和输出文件的扩展名分别是.in和.out。

5.程序应从输入文件读取数据,并严格地按照规定的输出格式将结果输出到输出文件中。

输入数据文件和输出数据文件都与程序在同一个目录中,由于程序所在目录是不确定的,因此不允许在程序中含有盘符信息和任何形式的路径信息。

6.选手在竞赛结束时应在D盘根目录下建立以参赛号命名的文件夹,并将所完成各题的源程序文件放到该文件夹中。

测试以评测系统编译的可执行文件为准,测试系统使用的是规范的编译指令处理源程序,没有附加任何编译选项,请选手按照考试机器上语言环境的默认配置来编译调试自己的程序。

题目1.搬砖头(rock)小可可一直对中国五千年的古老文明非常感兴趣,学习历史知识之余,他报名参加了少年考古队,跟随正式的考古队进行考古发掘,通过实践来更好的领会书本知识。

这次考古队发现了一个非常巨大的古墓,具有非常高的考古价值,小可可随队来到了考古现场。

经过紧张的发掘,古墓的墓道终于显露出来,但是它被一块块方砖封住了,现在小可可的任务就是帮助考古队将这些方砖移走,打通墓道。

由于这些保存完好的古代方砖也是珍贵的文物,所以规定一次最多只能搬三块砖。

小可可在搬砖的过程中一直在思考一个问题,他很想知道将这些砖头搬走共有多少种不同的搬法。

例如,现在总共有4个砖头,那么可以选择的方法有以下7种:1,1,1,1(分4次搬完,每次搬一个砖头)1,2,1(分3次搬完,第一次搬一个,第二次搬两个,第三次搬一个)1,1,2(分3次搬完,第一次搬一个,第二次搬一个,第三次搬两个)2,1,1(分3次搬完,第一次搬两个,第二次搬一个,第三次搬一个)2,2(分2次搬完,第一次搬两个,第二次搬两个)1,3(分2次搬完,第一次搬一个,第二次搬三个)3,1(分2次搬完,第一次搬三个,第二次搬一个)你能不能帮助小可可解决这个问题呢?输入:共一行。

AHCPC2021安徽省机器人大赛程序设计比赛省赛本科组题目

安 徽 省 机 器 人 大 赛程 序 设 计 赛 道( 本 科 组 )比赛试题2021年9月目 录A. 数7 (3)B. 恢复排列 (4)C. 连通块 (5)D. 持续攻击 (6)E. 字符串排序 (7)F. 道路维修 (8)G. 连边问题 (9)H. 数字谜盘 (11)I. 病毒 (12)J. 计分板 (14)K. 毒斗罗,群战yyds (15)A. 数7描述给定N个正整数,每个数大小不超过3,那么最多能将这N个数分为多少个组,使得每一组的和都是7的倍数?输入多组数据,第一行一个整数T表示数据组数。

每组数据第一行一个整数N,第二行三个整数x,y,z,分别表示1的个数,2的个数,3的个数,保证x+y+z=N,x+2y+3z能被7整除。

1 <= T <= 1000, 1 <= N <= 100。

输出输出T行,每行一个整数表示答案。

样例输入样例输出342 1 160 4 2 10061 24 15 1 2 22B. 恢复排列描述有一个1到N的排列P,给定P中任意两数的大小关系,求恢复这个排列。

输入第一行一个整数N,接下来N行,每行N个数。

每个数表示第i行第j列的值Pij,当Pij为-1表示Pi<Pj,为1表示Pi>Pj,为0表示Pi=Pj。

1 <= N <= 1000输出输出一行N个数,表示排列P。

样例输入 样例输出5 4 2 3 150 1 1 1 1-1 0 1 1 1-1 -1 0 -1 1-1 -1 1 0 1-1 -1 -1 -1 0C. 连通块描述给定一个长N的序列A,对于所有二元组(i,j) (1<=i<=n,1<=j<=n),如果满足i<j并且Ai>Aj,那么就在i和j之间连接一条边,这样最终得到一个无向图G。

那么现在你需要求出无向图G的最大连通块的点数。

输入第一行一个整数N,接下来一行N个整数,表示序列A。

2013-2014合肥工业大学宣城校区ACM-ICPC第一次练习赛试题

样例输入
445 11 13 21 33 34 000
样例输出
**10 3421 *3*2 13*2
时限
1s
gx
gx
第1页共7页
HFUTXCACM-2014 比赛试题(第一次练习赛,6 题 2 小时)
Problem B 优美的串
题目描述
小宣是一位追求完美的同学,他喜欢收集一些奇特的东西。这次他准备收集一些优美的串 , 所谓最优美的串就是指串正反读都是相同的(例如 ABCBA,正反读都相同),我们把最优 美的串的排斥度定义为 0。(注意,所有长度为一位的串都是最优美的串。) 当然啦,有些串虽然不是最完美的,但小宣也是不怎么排斥的。若 Ai,Bi 分别为一个串的正 反表示, Ai 和 Bi 的 ASCII 序差值绝对值的和就是整个串的排斥度,例如 ABCBE 的排斥度 就是
HFUTXCACM-2014 比赛试题(第一次练习赛,6 题 2 小时)
Problem A 扫雷
题目描述
大家都玩过扫雷游戏吧。简单来说,扫雷游戏有一个 W×H 的雷盘,每个格子可以是数字 也可以是地雷,若是数字表示在其周围的八个方块中共有多少个雷,游戏的目的就是找出所 有的雷。 本题要完成的任务很简单,给出雷盘的长宽、雷的个数和每个雷的坐标,输出最后的雷盘 。
输出格式
每行输出一个符合条件的优美的串和该串的排斥度(按输入顺序输出),以空格隔开
样例输入
28 ABCBA ABCBE
样例输出
ABCBA 0 ABCBE 8
时限
1s
gx
gx
第2页共7页
HFUTXCACM-2014 比赛试题(第一次练习赛,6 题 2 小时)
Problem C 黑色星期五
题目描述

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

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的数就可以了。

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

2018年安徽省机器人大赛程序设计竞赛
目录A.数7
B.编译错误
C.做操的时候要排好队D.判重
E.最长上升字串
F.雄伟的城堡
G.然后打5
H.运货卡车
I.最大矩形框
J.数列分段
K.数数字
A.数7
时间限制: 3s
描述
求整数序列中位置L到位置R中一共有多少个7。

对于每个数7的个数的定义为,十进制各个位置上一共有多少个7,以及能够被7整除的次数。

输入
第一行是一个整数T,代表测试数据的组数。

每组数据中两个整数L,R。

其中T≤50,L<R<105。

输出
共T行,共有多少个7。

样例输入
样例输出
提示
第一组样例中1到10中,只有7被计数,它十进制下有7并且是7的倍数,所以被计数2次。

第二组样例中47有1个7,49可以被7整除2次,所以共被计数3次。

B.编译错误
时间限制: 3s
描述
在程序员编写程序的时候,通常会引用其他文件,而引用的文件也会引用其它的头文件。

但是出现循环引用的现象编译时便会报错。

例如A引用了B,B引用了C,C引用了A,那么就产生了循环引用(Circular reference)。

考虑另外一个情况,A引用了B和C,B引用D,C引用D,虽然D被引用了两次,但是没有出现循环引用。

输入
第一行是一个整数T,代表测试数据的组数。

每组数据中第一行是一个整数n,代表有多少个引用关系。

接下来n行每行有2个字符串a,b,用空格分隔,代表a引用了b。

其中T≤50,
n≤105,每个字符串长度不超过100。

输出
共T行。

若不会产生编译错误则输出Passed,否则输出Failed。

样例输入
样例输出
C.做操的时候要排好队
时间限制: 3s
描述
同学们在做早操时,应该按照身高从低到高排好队。

但是总是有人不好好排队,老师在审查时会对没有排好的队伍扣除一定的分数。

扣的分数被定义为,找到三个人Ai,Aj,Ak,其中i<j<k,分数为max(0,(Ai-Aj))+max(0,(Aj-Ak))。

找到一组i,j,k 使这个分数最大即是扣除的分数。

输入
第一行是一个整数T,代表测试数据的组数。

每组数据中第一行是一个整数n,代表有一共有多少个人。

第二行共有n个整数,代表n个人的身高。

其中T≤50,n≤105,每个数的大小不超过1000。

输出
共T行。

扣除的分数。

样例输入
样例输出
D.判重
时间限制: 3s
描述
小七初始有n个数的样本集。

现在又新加了m个数,他想知道这m个数是否已经在这n个数之中了。

但是他判断是否有重复的方式和常人有些不同。

对于样本集内的任意一个数x,他先将x二进制的第2, 5, 7, 10, 13, 14, 17, 18位取反,生成新的8个数。

例如x是7(00111),那么第一个数就是5(00101),第二个数是23(10111)......依次类推。

然后将他表格上这8个数的位置全部变为1(初始整个表格全部为0)。

判断重复时,若一个数x产生的8个数,在表格内全部为1,就认为这个数x和样本集内的数有重复,否则认为没有重复。

输入
输入T,代表T组数据。

每组数据初始输入n, m。

代表n个样本以及m个需要判断的数。

接下来n+m行是n个样本以及m个需要判断的数,样本在前。

对于这m个数,每个数输出yes 或者no。

m组数据相互独立,即这m个数都不会新加入到样本集内。

其中T≤50,
n,m≤105。

输出
共T行,每行共m个字符串,重复输出yes,否则输出no
样例输入
样例输出
E.最长上升字串
时间限制: 3s
描述
给定n个整数,对其进行m次查询。

每次查询是一个范围l到r,求出l到r的最长上升连续子串。

上升连续子串的定义为一个连续的子串且严格递增。

输入
第一行是一个整数T,代表测试数据的组数。

每组数据中第一行是一个整数n,m,代表有一共有n个人,m个查询。

第二行共有n个整数,接下来m行是m 次查询,每行两个整数l,r。

输出
共T行,每行m个整数,代表最长上升连续字串。

其中T≤50,m≤105,每个数的大小不超过109。

样例输入
样例输出
F.雄伟的城堡
时间限制: 3s
描述
在一个群岛上,有一个富可敌国的大富翁。

他打算在这个群岛上建造一个最大城堡,也就是群岛上最大的岛屿。

输入
第一行是一个整数T,代表测试数据的组数。

每组数据中第一行是两个整数n,m,代表地图的大小。

接下来n行每行共m个整数。

0代表海洋,1代表陆地。

其中T≤50,n,m≤200。

输出
共T行,最大的面积。

样例输入
样例输出
G. 然后打5
时间限制: 5s
描述
《炉石传说》是一款考验技(shen)术(chou)的电子游戏,即使你没有玩过这个游戏也没有关系。

《炉石传说》里有一张萨满卡牌叫做连环爆裂,它的效果是等概率的造成3-6点伤害。

而游戏获胜的条件是将对方英雄的血量全部打掉。

例如对方英雄还有5点生命值,你有1张连环爆裂,那么你获胜的概率为。

在本题中你无需考虑法力值消耗。

输入
第一行是一个整数T,代表测试数据的组数。

接下来的T行每行有2个整数n,h,n代表你一共可以释放的连环爆裂的个数,h代表敌方英雄的血量。

其中T≤50,n≤5000,h≤30000。

输出格式
共T行,每行是一个小数,保留到小数点后6位。

样例输入
样例输出
H.运货卡车
时间限制: 5s
描述
在一个运输公司中有很多的卡车,每个卡车都可以装载重量为w的货物。

有若干个需要运输的货物,每个货物都有一个质量m。

这个运输公司对于这些货物的装载方式策略是,每一次尽可能装更多质量的货物,在有多种可以装载最多质量的货物的方式时,会选择货物下标字典序最小的一组。

例如货物的质量为4 3 2 1,卡车能够装载的质量为5时,第一次会选择4 1而不是2 3。

输入
第一行是一个整数T,代表测试数据的组数。

每组样例中,第一行有两个整数n,w,代表有n个货物,每个卡车可以装载质量w的货物。

接下来一行有n 个数字,代表每个货物的质量。

其中T≤20,n,w≤1000。

每个货物的质量不会超过w。

输出
共T行,输出所需要的卡车数量。

样例输入
样例输出
I.最大矩形框
时间限制: 5s
描述
有一个01的大矩阵,找到一个最大由1围成的矩形框的面积。

输入
第一行是一个整数T,代表测试数据的组数。

每组样例中,第一行有两个整数n,m,代表有大矩阵的大小,接下来是一个由01组成的大矩阵。

其中T≤10,n,m≤200。

输出
最大由1围成的矩形框的面积。

样例输入
样例输出
J.数列分段
时间限制: 3s
描述
有n个整数,分成m段。

使每一段的和的最小值尽可能的大。

输入
第一行是一个整数T,代表测试数据的组数。

每组样例中,第一行有两个整数n,m,接下来一行是n个整数。

其中T≤50,n,m≤105
输出
尽可能的大的每一段的和的最小值。

样例输入
样例输出
K.数数字
时间限制: 3s
描述
Alice和Bob进行一款质数游戏,Alice先说一个质数或者1,Bob再加上一个质数或者1。

不能超过目标数字,谁先喊道目标数字就获胜。

Alice和Bob都足够聪明,都会采用最有策略。

输入
第一行是一个整数T,代表测试数据的组数。

每组样例中,第一行有一个整数n,代表目标数字。

T≤20,n≤1018
输出
共T行,输出Alice win或者Bob win。

样例输入
样例输入。

相关文档
最新文档