安徽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安徽省机器人大赛程序设计比赛省赛本科组题目

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第一次练习赛试题

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程序设计大赛试题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编程比赛题

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

安徽省第六届安徽省大学生程序设计竞赛题目

安徽省第六届安徽省大学生程序设计竞赛题目

安徽省第六届大学生程序设计竞赛比赛题目安徽省高等学校计算机教育研究会安徽合肥2015.5.24A First BloodTime Limit: 3000/1000 MS (Java/Others)问题描述盖伦是个小学一年级的学生,在一次数学课的时候,老师给他们出了一个难题:老师给了一个正整数n,需要在不大于n的范围内选择三个正整数(可以是相同的),使它们三个的最小公倍数尽可能的大。

盖伦很想第一个解决这个问题,你能帮助盖伦拿到“first blood”吗?输入首先是一个正整数T,表示有T组测试数据每组测试数据是一个正整数n(1<=n<=10^6)输出对于每组测试数据,输出最大的最小公倍数,每个输出单独占一行样例输入297样例输出504210注意事项数据范围超出32位整数,可用long long或__int64表示64位整数B 求和Time Limit: 3000/1000 MS (Java/Others)问题描述对于正整数n,k ,我们定义这样一个函数f ,它满足如下规律...87654321)4,(...654321)3,(...654321)2,(...654321)1,(+++++----==++++---==+--++--==++-+-+-==k n f kn f kn f kn f 现在给出n 和k ,你的任务就是要计算),(k n f 的值。

输入首先是一个整数T ,表示有T 组数据接下来每组数据是n 和k(810,1≤≤k n )输出打印出f (n , k )的值,每个输出单独占一行样例输入31 12 13 1样例输出-11 -2C LU的困惑Time Limit: 3000/1000MS (Java/Others)问题描述Master Lu 非常喜欢数学,现在有个问题:在二维空间上一共有n个点,LU每连接俩个点,就会确定一条直线,对应有一个斜率。

现在LU把平面上所有点中任意两点连接成一条线,并将这条线的斜率加入一个集合(若斜率不存在则不计入集合),他想知道这个集合中有多少元素。

ACM比赛试题

ACM比赛试题

The 35th ACM-ICPC Asia Regional Contest (Hangzhou)Contest SectionOctober 24, 2010Sponsored by IBM & AlibabaZhejiang Sci-Tech UniversityThis problem set should contain 10 problems on numbered 24 pages. Please inform a runner immediately if something is missing from your problem set.Problem A. Naughty fairiesDescriptionOnce upon a time, there lived a kind of fairy in the world. Those fairies could hear the voice of fruit trees, and helped people with a harvest. But people did n’t know that fruits are also those fairies’ favorite food. After the fairies ate people’s fruits, they always did something to cover it up.One day a little fairy named Lily flew into an orchard and found a large peach tree. Hungry as Lily was, she started eating without thinking until her stomach was full. In the fairy world, when a fairy ate the fruits in a fruit tree, sometimes the fruit tree would feel honored and bore more fruits immediately. That’s why sometimes the number of fruits in a tree got increased after a fairy ate fruits of that tree.But the fairies didn’t want people to find out weird things such as fruits become more or less suddenly. Lily decided to use a magic spell so that the orchard owner couldn’t find the change of the number of p eaches.Suppose there were N peaches on a tree originally and there were M peaches left after Lily was full. M may be greater than, less than or equal to N. All M peaches were visible at first, and Lily wanted to make an illusion so that exactly N peaches are visible.Lily can do 3 kinds of spell to change the total visible number of peaches:1) “PAPADOLA”:This spell would increase the number of visible peaches by one.2) “EXPETO POTRONUM”:This spell would double the number of visible peaches.3) “SAVIDA LOHA”:This spell would decrease the number of visible peaches by one. Each spell would take one minute and Lily wanted to finish as fast as possible. Now please tell Lily the least time she needs to change the number of visible peaches to N.InputThere are several test cases, ended by “0 0”.For each test case, there are only one line containing two numbers separated by a blank, N and M, the original numbers of peaches and the numbers of peaches left(0<N,M<10500).There is no leading zero.OutputFor each test case, you should output just a number K indicating the minimum time (in minutes) Lily needed to finish her illusion magic.Sample Input5 21 9986 320 0Sample Output29812Problem B. Prison BreakDescriptionRompire is a robot kingdom and a lot of robots live there peacefully. But one day, the king of Rompire was captured by human beings. His thinking circuit was changed by human and thus became a tyrant. All those who are against him were put into jail, including our clever Micheal#1. Now it’s time to escape, but Micheal#1 needs an optimal plan and he contacts you, one of his human friends, for help.The jail area is a rectangle contains n×m little grids, each grid might be one of the following:1) Empty area, represented by a capital letter ‘S’.2) The starting position of Micheal#1, represented by a capital letter ‘F’.3) Energy pool, represented by a capital letter ‘G’. When entering a n energy pool, Micheal#1 can use it to charge his battery ONLY ONCE. After the charging, Micheal#1’s batt ery will become FULL and the energy pool will become an empty area. Of course, passing an energy pool without using it is allowed.4) Laser sensor, represented by a capital letter ‘D’. Since it is extremely sensitive, Micheal#1 cannot step into a grid with a laser sensor.5) Power switch, represented by a capital letter ‘Y’. Once Micheal#1 steps into a grid with a Power switch, he will certainly turn it off.In order to escape from the jail, Micheal#1 need to turn off all the power switches to stop the electric web on the roof—then he can just fly away. Moving to an adjacent grid (directly up, down, left or right) will cost 1 unit of energy and only moving operation costs energy. Of course, Micheal#1 cannot move when his battery contains no energy.The larger the battery is, the more energy it can save. But larger battery means more weight and higher probability of being found by the weight sensor. So Micheal#1 needs to make his battery as small as possible, and still large enough to hold all energy he need. Assuming that the size of the battery equals to maximum units of energy that can be saved in the battery, and Micheal#1 is fully charged at the beginning, Please tell him the minimum size of the battery needed for his Prison break.InputInput contains multiple test cases, ended by 0 0. For each test case, the first line contains two integer numbers n and m showing the size of the jail. Next n lines consist of m capital letters each, which stands for the description of the jail.You can assume that 1<=n,m<=15, and the sum of energy pools and power switches is less than 15.OutputFor each test case, output one integer in a line, representing the minimum size of the battery Micheal#1 needs. If Micheal#1 can’t escape, output -1.Sample Input5 5GDDSSSSSFSSYGYSSGSYSSSYSS0 0Sample Output4Problem C. To Be an Dream Architect DescriptionThe “dream architect” is the key role in a team of “dream extractors” who enter other’s dreams to steal secrets. A dream architect is responsible for crafting the virtual world that the team and the target will dream into. To avoid the target noticing the world is artificial, a dream architect must have powerful 3D imagination.Cobb uses a simple 3D imagination game to test whether a candidate has the potential to be an dream architect. He lets the candidate imagine a cube consisting of n×n×n blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked (1, 1, 1) and the diagonally opposite block is marked (n, n, n). Then he tells the candidate that the blocks on a certain line are eliminated. The line is always parallel to an axis. After m such block eliminations, the candidate is asked to tell how many blocks are eliminated. Note that one block can only be eliminated once even if it is on multiple lines.Here is a sample graph according to the first test case in the sample input:InputThe first line is the number of test cases.In each test case, the first line contains two integers n and m( 1 <= n <= 1000, 0 <= m <= 1000).,meaning that the cube is n x n x n and there are m eliminations.Each of the following m lines represents an elimination in the following format:axis_1=a, axis_2=bwhere axis_i (i=1, 2) is ‘X’ or ‘Y’, or ‘Z’ and axis_1 is not equal to axis_2. a and b ar e 32-bit signed integers.OutputFor each test case output the number of eliminated blocks.Sample Input23 2Y=1,Z=3X=3,Y=110 2X=3,Y=3Y=3,Z=3Sample Output519Problem D. GomokuDescriptionYou are probably not familiar with the title, “Gomoku”, but you must have played it a lot. Gomoku is an abstract strategy board game and is also called Five in a Row, or GoBang. It is traditionally played with go pieces (black and white stones) on a go board (19x19 intersections). Nowadays, standard chessboard of Gomoku has 15x15 intersections. Black plays first, and players alternate in placing a stone of their color on an empty intersection. The winner is the first player to get an unbroken row of five or more stones horizontally, vertically, or diagonally.For convenience, we coordinate the chessboard as illustrated above. The left-bottom intersection is (0,0). And the bottom horizontal edge is x-axis, while the left vertical line is y-axis.I am a fan of this game, actually. However, I have to admit t hat I don’t have a sharp mind. So I need a computer program to help me. What I want is quite simple. Given a chess layout, I want to know whether someone can win within 3 moves, assuming both players are clever enough. Take the picture above for example. There are 31 stones on it already, 16 black ones and 15 white ones. Then we know it is white turn. The white player must place a white stone at (5,8). Otherwise, the black player will win next turn. After that, however, the white player also gets a perfect situation that no matter how his opponent moves, he will win at the 3rd move.So I want a program to do similar things for me. Given the number of stones and positions of them, the program should tell me whose turn it is, and what will happen within 3 moves.InputThe input contains no more than 20 cases.Each case contains n+1 lines which are formatted as follows.nx1 y1 c1x2 y2 c2......x n y n c nThe first integer n indicates the number of all stones. n<=222 which means players have enough space to place stones. Then n lines follow. Each line contains three integers: x i and y i and c i. x i and y i are coordinates of the stone, and ci means the color of the stone. If c i=0 the stone is white. If c i=1 the stone is black. It is guaranteed that 0<=x i,y i<=14, and c i=0 or 1. No two stones are placed at the same position. It is also guaranteed that there is no five in a row already, in the given cases.The input is ended by n=0.OutputFor each test case:First of all, the program should check whose turn next. Le t’s call the player who will move next “Mr. Lucky”. Obviously, if the number of the black stone equals to the number of white, Mr. Lucky is the black player. If the number of the black stone equals to one plus the numbers of white, Mr. Lucky is the white player. If it is not the first situation or the second, print “Invalid.”A valid chess layout leads to four situations below:1)Mr. Lucky wins at the 1st move. In this situation, print :Place TURN at (x,y) to win in 1 move.“TURN” must be replaced by “black” or “white” according to the situation and (x,y) is the position of the move. If there are different moves to win, choose theone where x is the smallest. If there are still different moves, choose the one where y is the smallest.2)Mr. Lucky’s opp onent wins at the 2nd move. In this situation, print:Lose in 2 moves.3)Mr. Lucky wins at the 3rd move. If so, print:Place TURN at (x,y) to win in 3 moves.“TURN” should replaced by “black” or “white”, (x,y) is the position where the Mr.Lucky should place a stone at the 1st move. After he place a stone at (x,y), no matter what his opponent does, Mr. Lucky will win at the 3rd step. If there are multiple choices, do the same thing as described in situation 1.4)Nobody wins within 3 moves. If so, print:Cannot win in 3 moves.Sample Input313 3 13 4 03 5 03 6 04 4 14 5 14 7 05 3 05 4 05 5 15 6 15 7 15 9 16 4 16 5 16 6 06 7 16 8 06 9 07 5 17 6 07 7 17 8 17 9 08 5 08 6 18 7 08 8 18 9 09 7 110 8 017 7 117 7 0Sample OutputPlace white at (5,8) to win in 3 moves. Cannot win in 3 moves.Invalid.Problem E. GunshotsDescriptionPresident Bartlet was shot! A group of terrorists shot to the crowd when President Bartlet waved to cheering people after his address. Many people were shot by the irrational bullets. Senior FBI agent Don Epps takes responsibility for this case. According to a series of crime scene investigation, including analyzing shot shells, replaying video from closed-circle television and collecting testimony by witnesses, Don keeps all the information about where and how the terrorists shot to crowd, as well as the location of every single person when the gun shoot happened. Now he wants to know how many gunshot victims are there in this case.Imagine that each target person can be regarded as a polygon (can be concave or self-intersecting) and each gunshot can be regarded as a half-line. The bullet will be stopped by the first person it shoots. A person can be shot in three ways:To simplify the problem, we assume that any two polygons can be completely separated by a line. Also each start point of the gunshot can be separated from each polygon by a line. Now given M people and N gunshots, please work out which person has been shot by each bullet.InputThere are multiple test cases in the input. The first line of the input file is an integer T demonstrating the number of test cases. (T<=10).For each test case, the first line is an integer N, representing the number of people (polygons). Following lines demonstrates the polygons. For the i th polygon (0<=i<N), the first line is an integer Q i , representing the number of edges of this polygon. In each of the following Q i lines, there are two real numbers x i and y i representing a point. Every pair of adjacent points demonstrate an edge of this polygon (i.e. (x i , y i ) to (x i+1, y i+1) is an edge, in which 0<=i<Q i -1), and (x Qi-1, y Qi-1) to (x 0, y 0) also demonstrates an edge of this polygon.PersonPerson Person 1. Normal shot 2. The bullet’s path isparallel to an edge 3. The bullet’s path is tangent to an vertexThen there is a line contains an integer M representing the number of gunshots. In the following M lines, each line contains four real numbers x, y, dx and dy, representing the start point (x, y) and direction vector (dx, dy) of that gunshot.In all test cases, we assume that 0< N<=100, 0<Q i<=1000, 0<M<=10000.OutputFor each test case, output contains M lines and the i th line demonstrates the result of the i th gunshot.If the i th gunshot shoots the j th polygon, the i th line contains “HIT j”, otherwise it contains a word “MISS” (means that it does not shoot any target). The polygons are numbered in the order of their appearance in the input file, and the numbers start from 0.At the end of each test case, please output a single line with “*****”.Sample Input1140 01 10 11 02-1 0 1 0-2 0 -1 0Sample OutputHIT 0MISS*****HintThe figure of the first case in the samples is as follows:Problem F. Rotational PaintingDescriptionJosh Lyman is a gifted painter. One of his great works is a glass painting. He creates some well-designed lines on one side of a thick and polygonal glass, and renders it by some special dyes. The most fantastic thing is that it can generate different meaningful paintings by rotating the glass. This method of design is called “Rotatio nal Painting (RP)” which is created by Josh himself.You are a fan of Josh and you bought this glass at the astronomical sum of money. Since the glass is thick enough to put erectly on the table, you want to know in total how many ways you can put it so that you can enjoy as many as possible different paintings hiding on the glass. We assume that material of the glass is uniformly distributed. If you can put it erectly and stably in any ways on the table, you can enjoy it.More specifically, if the polygonal glass is like the polygon in Figure 1, you have just two ways to put it on the table, since all the other ways are not stable. However, the glass like the polygon in Figure 2 has three ways to be appreciated.Pay attention to the cases in Figure 3. We consider that those glasses are not stable.InputThe input file contains several test cases. The first line of the file contains an integer T representing the number of test cases.For each test case, the first line is an integer n representing the number of lines of the polygon. (3<=n<=50000). Then n lines follow. The i th line contains two real number x i and y i representing a point of the polygon. (x i, y i) to (x i+1, y i+1) represents a edge of the polygon (1<=i<n), and (x n,y n) to (x1, y1) also represents a edge of the polygon. The input data insures that the polygon is not self-crossed.OutputFor each test case, output a single integer number in a line representing the number of ways to put the polygonal glass stably on the table.Sample Input240 0100 099 11 160 00 101 101 110 110 0Sample Output23HintThe sample test cases can be demonstrated by Figure 1 and Figure 2 in Description part.Problem G. Traffic Real Time Query System DescriptionCity C is really a nightmare of all drivers for its traffic jams. To solve the traffic problem, the mayor plans to build a RTQS (Real Time Query System) to monitor all traffic situations. City C is made up of N crossings and M roads, and each road connects two crossings. All roads are bidirectional. One of the important tasks of RTQS is to answer some queries about route-choice problem. Specifically, the task is to find the crossings which a driver MUST pass when he is driving from one given road to another given road.InputThere are multiple test cases.For each test case:The first line contains two integers N and M, representing the number of the crossings and roads.The next M lines describe the roads. In those M lines, the i th line (i starts from 1)contains two integers X i and Y i, representing that road i connects crossing X i and Y i (X i≠Y i).The following line contains a single integer Q, representing the number of RTQs. Then Q lines follows, each describing a RTQ by two integers S and T(S≠T) meaning that a driver is now driving on the road s and he wants to reach road t . It will be always at least one way from road s to road t.The input ends with a line of “0 0”.Please note that: 0<N<=10000, 0<M<=100000, 0<Q<=10000, 0<X i,Y i<=N, 0<S,T<=M OutputFor each RTQ prints a line containing a single integer representing the number of crossings which the driver MUST pass.Sample Input5 61 22 33 44 53 522 32 40 0Sample Output 01Problem H. National Day ParadeDescriptionThere are n×n students preparing for the National Day parade on the playground. The playground can be considered as a n×m grid. The coordinate of the west north corner is (1,1) , and the coordinate of the east south corner is (n,m).When training, every students must stand on a line intersection and all students must form a n×n square. The figure above shows a 3×8 playground with 9 students training on it. The thick black dots stand for the students. You can see that 9 students form a 3×3 square.After training, the students will get a time to relax and move away as they like. To make it easy for their masters to control the training, the students are only allowed to move in the east-west direction. When the next training begins, the master would gather them to form a n×n square again, and the position of the square doesn’t matter. Of course, no student is allowed to stand outside the playground.You are given the coordinates of each student when they are having a rest. Your task is to figure out the minimum sum of distance that all students should move to form a n×n square.InputThere are at most 100 test cases.For each test case:The first line of one test case contain two integers n,m. (n<=56,m<=200)Then there are n×n lines. Each line contains two integers, 1<=X i<=n,1<= Y i<=m indicating that the coordinate of the i th student is (X i , Y i ). It is possible for more than one student to stand at the same grid point.The input is ended with 0 0.OutputYou should output one line for each test case. The line contains one integer indicating the minimum sum of distance that all students should move to form a n×n square. Sample Input2 1682 1011 1271 1052 900 0Sample Output41Problem I. SearchlightsDescriptionThere is a piece of grids land of size n×m. Chandler and his team take responsibility to guard it. There are some searchlights on some pieces and each of them has a capability to lighten a distance towards four directions: north, south, east and west. Different searchlight has different lightening capability shown in levels. Searchlight with level k means that it can lighten k grids (including the gird that the searchlight stands in) along any of the four directions. Shown in following figure, there is a searchlight of level 3 and the shadow grids are ones that can be lightened by it. Particularly, searchlight of level 1 means that it can only lighten the grid in which the searchlight stands.Figure: A searchlight of Level 3Each searchlight has a maximum level. You can decrease a searchlight’s level to save the energy. A searchlight whose maximum level is k can be turned to level k, k-1, k-2, …, 1 and 0. Level 0 means turning off the searchlight.A grid is well-guarded if and only if at least one of the following two conditions is satisfied:1.There is a searchlight in this grid, and it is not switched to level 0 (the light is on).2.The grid is lightened by at least two searchlights. One lightens it in horizontaldirection (east or west), and another lightens it in vertical direction (north or south).Chandler asks you to help finding a solution that he can turn on some of the searchlights so that:1.All the grids are well-guarded.2.All the searchlights turned on are in a same level.3.That same level mentioned above is as small as possible.More specifically, if you choose a same level Q, then all the searchlights whose maximum level are less than Q have to be turned off. Please help him to find a solution with the minimum same level.InputThe input file contains several test cases.For each test case, the first line is two integers n and m, representing a grids land of size n×m. (0<n<=100, 0<m<=10000). Following n lines describe an n×m matrix in which a i,j means the maximum level of the searchlight in grid (i, j). a i,j can be zero, which means there is no searchlight on that grid. For all the cases, a i, j<=10000.The input file ends with a line containing two zeros.OutputFor each test case, output a single line with an integer, representing the minimum level you have found. If there is no such a solution, output “NO ANSWER!”Sampl e Input2 20 23 02 20 21 00 0Sampl e Output2NO ANSWER!Problem J. Infinite monkey theorem DescriptionCould you imaging a monkey writing computer programs? Surely monkeys are smart among animals. But their limited intelligence is no match for our human beings. However, there is a theorem about monkeys, and it states that monkeys can write everything if given enough time.The theorem is called “Infinite monkey theorem”. It states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type any given text, which of course includes the programs you are about to write (All computer programs can be represented as text, right?).It’s very easy to prove this theorem. A little calculation will show you that if the monkey types for an infinite length of time the probability that the output contains a given text will approach 100%.However, the time used is too long to be physically reasonable. The monkey will not be able to produce any useful programs even if it types until the death of the universe. To verify this and ensure that our human beings are not replaceable by monkeys, you are to calculate the probability that a monkey will get things right.InputThere will be several test cases.Each test case begins with a line containing two integers n and m separated by a whitespace (2<=n<=26, 1<=m<=1000). n is the number of keys on the typewriter and the monkey will hit these keys m times. Thus the typewriter will finally produce an output of m characters.The following n lines describe keys on the typewriter. Each line has a lower case letter and a real number separated by a whitespace. The letter indicates what the typewriter will produce if the monkey hits that key and the real number indicates the probability that the monkey will hit this key. Two hits of the monkey are independent of each other (Two different hits have the same probability for a same key), and sum of all the probabilities for each key is ensured to be 1.The last line of the test case contains a word composed of lower case letters. The length of the word will be less than or equal to 10.The input will end with a line of two zeros separated by a whitespace. This line should not be processed.OutputFor each test case, output one line containing the probability that the given word will appear in the typewriter’s output. The output should be in percentage format and numbers should be rounded to two digits after the decimal point.Sampl e Input4 10w 0.25o 0.25r 0.25d 0.25word2 10a 1.0b 0.0abc2 100a 0.312345b 0.687655abab0 0Sampl e Output2.73%0.00%98.54%。

acm数学竞赛试题及答案

acm数学竞赛试题及答案

acm数学竞赛试题及答案# 题目一:数列问题问题描述:给定一个数列 \( a_1, a_2, a_3, \ldots, a_n \),数列中每个元素都是正整数,且满足 \( a_i = a_{i-1} + a_{i-2} \) 对于所有\( i \geq 3 \)。

如果 \( a_1 = 1 \) 且 \( a_2 = 1 \),请找出数列的第 \( n \) 项。

解答:根据题意,这是一个斐波那契数列。

第 \( n \) 项的值可以通过递归关系计算得出。

对于 \( n \) 的值,可以使用以下递归公式:\[ a_n = a_{n-1} + a_{n-2} \]其中,\( a_1 = 1 \) 和 \( a_2 = 1 \)。

因此,数列的前几项为 1, 1, 2, 3, 5, 8, 13, 21, ...。

对于任意的 \( n \),可以通过递归或动态规划方法计算出 \( a_n \)。

# 题目二:组合问题问题描述:从 \( n \) 个不同的元素中选择 \( k \) 个元素的所有可能组合的个数是多少?解答:这个问题可以通过组合数学中的二项式系数来解决。

从 \( n \) 个不同元素中选择 \( k \) 个元素的组合数 \( C(n, k) \) 可以用以下公式计算:\[ C(n, k) = \frac{n!}{k!(n-k)!} \]其中,\( n! \) 表示 \( n \) 的阶乘。

# 题目三:几何问题问题描述:在一个直角坐标系中,给定三个点 \( A(x_1, y_1) \),\( B(x_2, y_2) \) 和 \( C(x_3, y_3) \)。

如果 \( \overrightarrow{AB} \) 和 \( \overrightarrow{AC} \) 是垂直的,求证 \( A \) 是直角三角形 \( ABC \) 的直角顶点。

解答:如果 \( \overrightarrow{AB} \) 和 \( \overrightarrow{AC} \) 垂直,那么它们的数量积(点积)应该为零。

黄淮学院ACM大赛初赛试题

黄淮学院ACM大赛初赛试题

信息工程学院第一届程序设计竞赛复赛试题T1【问题描述】一个正整数有可能可以被表示为n(n>=2)个连续正整数之和,如:15=1+2+3+4+515=4+5+615=7+8请编写程序,根据输入的任何一个正整数,找出符合这种要求的所有连续正整数序列。

【输入】一个正整数,以命令行参数的形式提供给程序。

【输出】在标准输出上打印出符合题目描述的全部正整数序列,每行一个序列,每个序列都从该序列的最小正整数开始、以从小到大的顺序打印。

如果结果有多个序列,按各序列的最小正整数的大小从小到大打印各序列。

此外,序列不允许重复,序列内的整数用一个空格分隔。

如果没有符合要求的序列,输出“NONE”。

样例1【输入】15【样例输出】1 2 3 4 54 5 67 8样例2【输入】16【样例输出】NONET2【问题描述】津津的零花钱一直都是自己管理。

每个月的月初妈妈给津津300元钱,津津会预算这个月的花销,并且总能做到实际花销和预算的相同。

为了让津津学习如何储蓄,妈妈提出,津津可以随时把整百的钱存在她那里,到了年末她会加上20%还给津津。

因此津津制定了一个储蓄计划:每个月的月初,在得到妈妈给的零花钱后,如果她预计到这个月的月末手中还会有多于100元或恰好100元,她就会把整百的钱存在妈妈那里,剩余的钱留在自己手中。

例如11月初津津手中还有83元,妈妈给了津津300元。

津津预计11月的花销是180元,那么她就会在妈妈那里存200元,自己留下183元。

到了11月月末,津津手中会剩下3元钱。

津津发现这个储蓄计划的主要风险是,存在妈妈那里的钱在年末之前不能取出。

有可能在某个月的月初,津津手中的钱加上这个月妈妈给的钱,不够这个月的原定预算。

如果出现这种情况,津津将不得不在这个月省吃俭用,压缩预算。

现在请你根据2004年1月到12月每个月津津的预算,判断会不会出现这种情况。

如果不会,计算到2004年年末,妈妈将津津平常存的钱加上20%还给津津之后,津津手中会有多少钱。

ACM算法题以及答案

ACM算法题以及答案
ACM算法题使用C++实现
在做这些题目之前必须了解vector(数组),list(链表)、deque(双端队列)、queue(队列),priority_queue(优先队列)Stack(栈)、set(集合)、map(键值对),mutilset、mutilmap。
stack堆栈,没有迭代器,支持push()方法。后进先出,top()返回最顶端的元素,pop()剔除最顶元素
定义queue对象的示例代码如下:
queue<int> q1;
queue<double> q2;
queue的基本操作有:
入队,如例:q.push(x);将x接到队列的末端。
出队,如例:q.pop();弹出队列的第一个元素,注意,并不会返回被弹出元素的值。
访问队首元素,如例:q.front(),即最早被压入队列的元素。
#include <vector>
vector属于std命名域的,因此需要通过命名限定,如下完成你的代码:
using std::vector; vector<int> v;
或者连在一起,使用全名:
std::vector<int> v;
建议使用全局的命名域方式:
using namespace std;
list不支持随机访问。所以没有 at(pos)和operator[]。
list对象list1, list2 分别有元素list1(1,2,3),list2(4,5,6) 。list< int>::iterator it;
list成员
说明
constructor
构造函数
destructor
析构函数

ACM程序设计试题及参考答案

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<<"只。

acm试题及答案

acm试题及答案

acm试题及答案ACM试题及答案试题 1: 给定一个整数数组,请找出数组中第二大的数。

答案:1. 对数组进行排序。

2. 数组排序后,倒数第二个元素即为第二大的数。

试题 2: 编写一个函数,计算给定字符串中字符出现的次数。

答案:```pythondef count_characters(s):count_dict = {}for char in s:if char in count_dict:count_dict[char] += 1else:count_dict[char] = 1return count_dict```试题 3: 判断一个数是否为素数。

答案:1. 如果数小于2,则不是素数。

2. 从2开始到该数的平方根,检查是否有因数。

3. 如果没有因数,则该数是素数。

试题 4: 实现一个算法,将一个整数数组按照奇数在前,偶数在后的顺序重新排列。

答案:```pythondef rearrange_array(arr):odd = []even = []for num in arr:if num % 2 == 0:even.append(num)else:odd.append(num)return odd + even```试题 5: 给定一个链表,删除链表的倒数第n个节点。

答案:1. 遍历链表,找到链表的长度。

2. 再次遍历链表,找到倒数第n个节点的前一个节点。

3. 将前一个节点的next指针指向当前节点的下一个节点。

4. 如果当前节点是头节点,则更新头节点。

试题 6: 编写一个函数,实现字符串反转。

答案:```pythondef reverse_string(s):return s[::-1]```试题 7: 给定一个整数数组,找出数组中没有出现的最小正整数。

答案:1. 遍历数组,使用哈希表记录出现的数字。

2. 从1开始,检查每个数字是否在哈希表中。

3. 第一个不在哈希表中的数字即为答案。

试题 8: 实现一个算法,计算斐波那契数列的第n项。

安徽ACM省赛试题

安徽ACM省赛试题

2018年安徽省机器人大赛程序设计竞赛目录A.数7B.编译错误C.做操的时候要排好队D.判重E.最长上升字串F.雄伟的城堡G.然后打5H.运货卡车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 使这个分数最大即是扣除的分数。

  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。

样例输入
样例输入。

相关文档
最新文档