ACM集训队选拔赛第一场题目
2013ACM月赛第I场正赛题目
![2013ACM月赛第I场正赛题目](https://img.taocdn.com/s3/m/b003104e312b3169a451a4e3.png)
北京理工大学珠海学院A-G共7题注意:题目难度与题号无关A老吴的棋盘游戏Time Limit: 1s Memory Limit: 256MProblem Description集训的结束带来的就是新学期的到来。
开学已久,ACMer们许久没A题也有些无聊了,不过最近老吴发现了一个游戏可以用来消磨时间。
其实就是一个棋盘游戏,它的规则是这样的,全场只有一颗棋子,初始坐标在(1,1)点,下一步只能往(1,2)(0,1)(2,1)三个方向移动。
后面该棋子也以这个规则移动。
对家提问恰好走N步且不经过已走过的点有多少种走法,而你只需回答有M种走法就行了。
大胆地去猜测具体规则吧,骚年。
Input有多组测试数据。
每行都有一个整数N(N<=20),当N小于或等于0时结束全部输入。
Output输出占一行,为对家提问的结果M。
Sample Input13Sample Output317AuthorBy-廖瑞华B老陈逛校园Time Limit: 1s Memory Limit: 256MProblem Description老吴的棋盘游戏好不好玩?不过瘾的话来做一个有意义的事吧,荔枝园去过么?没去过不要紧,我们的活动不在那里进行,在全校范围内,假设学校有N个地点,M条道路。
是这样的,有一天老陈出去校门口送pc坐车回家,回来时忽然心血来潮就把学校走了一圈。
他发现其实我们学校真的很大,只是我们都没去走过而已。
这样吧,你们去走遍北理珠校园?走归走,从2饭到图书馆有很多路径可以选择,你们应该寻找捷径。
走过后最好就给老陈画一张地图啦。
不过只需要给老陈路径的数据就可以了,绘制就由他来做吧。
大胆地去开发校园吧,别留遗憾。
Input有多组测试数据。
第一行都有2个整数N M(1<=N<=1000,0<=M<=10000),接下来有M行a b c,(1<=a,b<=N,0<=c<=10000),表示a与b之间有一条长度为c的道路。
ACM面试题-美国计算机程序选拔赛
![ACM面试题-美国计算机程序选拔赛](https://img.taocdn.com/s3/m/2e3bb6afdd3383c4bb4cd25e.png)
【试题一】青蛙相遇问题【题目描述】两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。
它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。
可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。
不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。
但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。
为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。
我们把这两只青蛙分别叫做青蛙A和青蛙B,并且规定纬度线上东经0度处为原点,由东往西为正方向,单位长度1米,这样我们就得到了一条首尾相接的数轴。
设青蛙A的出发点坐标是x,青蛙B的出发点坐标是y。
青蛙A一次能跳m米,青蛙B一次能跳n米,两只青蛙跳一次所花费的时间相同。
纬度线总长L米。
现在要你求出它们跳了几次以后才会碰面。
Input 输入只包括一行5个整数x,y,m,n,L,其中x≠y < 2000000000,0 < m、n < 2000000000,0 < L < 2100000000。
Output 输出碰面所需要的跳跃次数,如果永远不可能碰面则输出一行"Impossible"示例Sample Input1 2 3 4 5Sample Output4题目要求;1.程序应该可以运行:通过控制台输入数据,输出数据通过printf给出;2.程序结构明了逻辑缜密、清晰,符合编码规范;3.程序功能正确;程序要注意效率;并且要求根据输入及时确认是否能够相遇,如果不能相遇请及早退出程序;程序思路:说明:可以将青蛙的路线看坐是一个圆判断其坐标如果下一次跳动后将饶过原点则把坐标转换这样无论青蛙在哪个位置上都用坐标来表示它如果两只青蛙坐标相等则相遇如果两只青蛙开始的坐标不一样但是速度一样那么将永远不能相遇【试题二】田忌赛马此题就是经典的田忌赛马,田忌和他的对手分别有n匹马,分别给出田忌的马的速度和对手的马的速度。
河南科技大学ACM选拔赛试题
![河南科技大学ACM选拔赛试题](https://img.taocdn.com/s3/m/c2dcc7ee0975f46527d3e149.png)
河南科技大学ACM-ICPC选拔赛试题承办:电子信息工程学院地点:开园校5区-511机房时间:2011年5月18日-比赛规则考试时间:3小时2:30~5:30)题目:共4题评分:以正确答题数多且完成用时少者为优胜1.中国象棋【问题描述】在中国象棋中,马是一个非常有用的棋子,它能从任意一点出发遍历整个棋盘。
请你编写一个程序,判断一个马能否从指定的起始位置经过一定的步数跳到另一个位置。
棋盘有9*10个交叉点,编号从(1、1)到(9.10),马只能能走日字型,跳的时候不能跳出棋盘。
【标准输入】有多个测试用例,输入第一行包含一个正整数K(0<K<1000),表示有K组测试数据。
每个测试用例包含一行为(SX、SY、EX、EY、N)(1<=N<=20),分别代表起始位置、结束位置和步数。
【标准输出】对于每个测试用例,输出一行,如果在N部内能走到,则输出“YES”,否则输出“NO”。
【样例输入】11 1 5 5 10【样例输出】YES2.栈【问题描述】栈是在计算机中经常用到的一种数据结构,它限制仅在表的一端进行插入和删除运算的线性表。
栈的修改是按后进先出的原则进行。
每次退栈的总是当前栈中“最新”的元素,即最后进栈的元素,而最先插入的是被放在栈的底部,要到最后才能删除。
请编写一个程序,能得到栈经过一系列的操作后的数据元素的个数。
【标准输入】有多个测试用例,输入第一行包含一个正整数K(0<K<1000),表示有K组测试数据。
每个测试用例第一行包含一个正整数M(1<=M<=10000),表示有M个对栈的操作,以下包含M个正整数N(1<=N<=3),1表示进栈操作,2表示出栈操作,3表示取栈顶元素操作。
(当前栈为空时出栈操作不做任何操作)。
【标准输出】对于每个测试用例,输出一行,即当前栈的元素个数。
【样例输入】251 2 3 1 142 2 1 1【样例输出】223.摆数字【问题描述】用火柴摆数字是大家可能玩过的一个小游戏,用火柴能摆出以下的十个数字,每个数字需要一定量的火柴,如7需要3根火柴,而8需要7根火柴,请编写一个小程序,计算使用N 根火柴所能摆出的最小数字和最大数字。
ACM程序大赛选拔初赛试题 - 参考答案
![ACM程序大赛选拔初赛试题 - 参考答案](https://img.taocdn.com/s3/m/7d32d5a384868762caaed572.png)
《解方程》参考答案:
#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
ACM初步题及题解-推荐下载
![ACM初步题及题解-推荐下载](https://img.taocdn.com/s3/m/6397ca2bc281e53a5802fff8.png)
acm大赛试题及答案
![acm大赛试题及答案](https://img.taocdn.com/s3/m/d6b82f68773231126edb6f1aff00bed5b9f37387.png)
acm大赛试题及答案ACM大赛试题及答案1. 题目一:字符串反转问题描述:编写一个程序,输入一个字符串,输出其反转后的字符串。
输入格式:输入包含一个字符串,字符串长度不超过100。
输出格式:输出反转后的字符串。
示例:输入:hello输出:olleh答案:```pythondef reverse_string(s):return s[::-1]input_string = input().strip()print(reverse_string(input_string))```2. 题目二:计算阶乘问题描述:编写一个程序,输入一个非负整数n,输出n的阶乘。
输入格式:输入包含一个非负整数n,n不超过20。
输出格式:输出n的阶乘。
示例:输入:5输出:120答案:```pythondef factorial(n):if n == 0:return 1else:return n * factorial(n - 1)n = int(input())print(factorial(n))```3. 题目三:寻找最大数问题描述:给定一个包含n个整数的数组,找出数组中的最大数。
输入格式:输入包含一个整数n,表示数组的大小,随后是n个整数。
输出格式:输出数组中的最大数。
示例:输入:5 1 2 3 4 5输出:5答案:```pythonn = int(input())numbers = list(map(int, input().split()))max_number = max(numbers)print(max_number)```4. 题目四:判断闰年问题描述:编写一个程序,输入一个年份,判断该年份是否为闰年。
输入格式:输入包含一个整数,表示年份。
输出格式:如果输入的年份是闰年,则输出"Yes",否则输出"No"。
示例:输入:2000输出:Yes答案:```pythonyear = int(input())if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):print("Yes")else:print("No")```5. 题目五:斐波那契数列问题描述:编写一个程序,输入一个非负整数n,输出斐波那契数列的第n项。
acm竞赛试题及答案
![acm竞赛试题及答案](https://img.taocdn.com/s3/m/7efe556eec630b1c59eef8c75fbfc77da2699708.png)
acm竞赛试题及答案ACM(Association for Computing Machinery)竞赛是一项全球性计算机科学竞赛,旨在锻炼参赛者的问题解决能力和编程技巧。
每年都有数千名来自不同学校的学生参加这一挑战。
本文将提供一些最近的ACM竞赛试题以及相应的答案,帮助读者了解和学习竞赛题目的类型和解题思路。
1. 问题描述给定一个由N个整数组成的数组A,请编写一个程序,找出数组中两个不同元素的差的最小值。
2. 输入格式- 第一行包含一个整数N,表示数组A的长度。
- 第二行包含N个以空格分隔的整数,表示数组A中的元素。
3. 输出格式输出一个整数,表示数组中两个不同元素的差的最小值。
4. 示例输入:51 52 9 12输出:15. 解题思路该问题可以通过对数组进行排序,并比较相邻两个数的差值来求解。
首先,将数组A进行升序排序。
然后,遍历排序后的数组,依次计算相邻两个数的差值,并记录其中的最小值。
最后,返回这个最小差值即可。
6. 代码实现```pythondef min_difference(nums):nums.sort() # 对数组进行升序排序min_diff = float('inf') # 初始化最小差值为正无穷大for i in range(len(nums)-1):diff = abs(nums[i] - nums[i+1]) # 计算相邻两个数的差值min_diff = min(min_diff, diff) # 更新最小差值return min_diff# 输入处理N = int(input())A = list(map(int, input().split()))# 调用函数并输出结果result = min_difference(A)print(result)```7. 答案解析对给定的数组进行排序后,遍历数组计算相邻两个数的差值,并记录其中的最小值。
上述代码中,首先将数组A进行升序排序,然后使用一个变量`min_diff`来记录最小差值。
ACM选拔赛试题
![ACM选拔赛试题](https://img.taocdn.com/s3/m/4ad9b2ddad51f01dc281f1c1.png)
ACM选拔赛试题
注意:程序文件命名为:Test+题号
1、已知四位数3025有一个特殊性质:它的前两位数30和后两位数25的和是55,而55的平方刚好等于该数(55*55=3025),编写一个程序求出所有的具有这种性质的四位数。
2、有的三位数很独特,它们每位上的数字互不相同且都不大于7,特别是十位数正好是百位数和个位数之差,编写程序求所有这样的三位数。
3、某电台组织一次智力竞赛,计划奖励30人。
准备了50件奖品,得一等奖者可得3件,二等奖可得2件,三等奖可得1件。
希望把所有奖品都发到获奖者手中,请编程找出所有的设奖方案(即各等奖各有多少人)。
4、修改31743的某一位数字,使之成为823的倍数。
5、在自然数中,各位数字之和的11倍正好等于自身的自然数只有一个,编写程序请找出这个自然数。
6、小明的妈妈是负责分发单位工资的。
为了使分发时有足够的零钞,同时又尽量不使每个人领到的钱太零碎。
每个月她都要计算出各种面值的钞票(100元、50元、20元、10元、5元、2元、1元)各需多少张。
假设每个人的工资都是整数元,你能否为她设计一个程序,从键盘输入10个人的工资,再计算各种面值的钞票各需多少张?
7、4名专家对四款赛车进行评论:
A说:2号赛车是最好的。
B说:4号赛车是最好的。
C说:3号赛车不是最佳赛车。
D说:B说错了。
事实上,只有一款赛车最佳,且只有一名专家说对了,其他3人说错了,请编程输出最佳赛车的车号,以及哪一位专家说对了。
ACM软件大赛之编程大赛题目(附部分答案)
![ACM软件大赛之编程大赛题目(附部分答案)](https://img.taocdn.com/s3/m/af07528981c758f5f71f6730.png)
ACM软件大赛之编程大赛比赛注意事项:●比赛时间为3小时(180分钟);比赛分两个阶段:第一阶段限时30分钟,完成公示的3题,第二阶段限时150分钟(事先完成第一阶段题目的小组可提前进入第二阶段);●比赛第一阶段的3道题目将在前期宣传中告知参赛选手,比赛第二阶段的题目将由赛事主席当场公布竞赛题目;●前两阶段题目分为三个分值(5分、10分、15分),第一阶段3道公示题都为5分;第二阶段总共15道题,根据不同的难度分值不同,分别为5道5分题,5道10分题,5道15分题;第一阶段参赛队员不可参考任何相关资料;第二阶段参赛队员可以携带诸如书,手册,程序清单等参考资料。
比赛过程中队员不得携带任何电子媒质的资料;参赛者可以选择自己擅长的语言(C,C++,JAVA等等)进行编写●考虑到大一和大二学生的知识掌握程度,大一参加选手一开始就会有10分的分数,最后总分是由所做题目及初始的10分相加得到。
●每组队员根据安排使用电脑,小组人数为两人的使用一台电脑,超过两人的使用两台电脑,每台的电脑配置完全相同;●各小组每做完一题或几题,必须交予评委老师运行,评委老师当场给分;●如在比赛中发现作弊等行为,将取消比赛资格。
第一阶段公示题目:题目一:(5分)打印以下图形,纵遵从字母顺序,行字符数遵从斐波那契数列ABCCDDDEEEEEFFFFFFFFGGGGGGGGGGGGG#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 time){int h=time/100;int m=time-100*h;return h<=12&&m<=59&&h>0?true:false;//12小时制}int main(){int time=0;int j(0);//总计数器while(time<1270){//max 12:59int t=time;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(time)){//cout<<n[3]<<n[2]<<":"<<n[1]<<n[0]<<"\n";//testj++;}time++;}cout<<"total: "<<j*2<<endl;}题目三:(5分)10进制的四位数中有几个符合如下特征:将其分别表示为16进制、10进制、12进制,在每种状态下,分别将各个位上的数相加,能得到3个相等10进制数。
acm大赛历年程序题
![acm大赛历年程序题](https://img.taocdn.com/s3/m/f4ae431fbf23482fb4daa58da0116c175f0e1eea.png)
acm大赛历年程序题
ACM大赛是一项计算机竞赛,每年都会发布一系列的程序题供
参赛者解答。
这些题目涵盖了各个计算机科学领域的知识,包括数
据结构、算法、图论、动态规划、数学等等。
以下是一些历年ACM
大赛的程序题的例子:
1. 最短路径问题,给定一个有向带权图,求两个节点之间的最
短路径。
可以使用Dijkstra算法或者Floyd-Warshall算法来解决。
2. 字符串处理问题,给定一个字符串,要求对其进行特定的处理,比如反转、删除重复字符等。
可以使用字符串操作和遍历来解决。
3. 数组操作问题,给定一个数组,要求对其进行特定的操作,
比如排序、查找最大/最小值、计算数组的平均值等。
可以使用排序
算法、查找算法和遍历来解决。
4. 动态规划问题,给定一个问题和一组限制条件,要求找到满
足条件的最优解。
可以使用动态规划的思想,将问题拆分成子问题
并逐步求解。
5. 图论问题,给定一个图,要求对其进行特定的操作,比如查找连通分量、判断是否存在环等。
可以使用图的遍历和深度优先搜索或广度优先搜索来解决。
6. 数学问题,给定一个数学问题,要求求解或验证某个数学定理或公式。
可以使用数学运算和推导来解决。
这些只是一小部分例子,ACM大赛的题目类型非常多样化,每年都会有新的题目发布。
参赛者需要具备扎实的计算机科学基础知识和良好的编程能力,才能在规定时间内解决这些问题。
黄淮学院ACM大赛初赛试题
![黄淮学院ACM大赛初赛试题](https://img.taocdn.com/s3/m/21c3b5aadd3383c4bb4cd2a3.png)
信息工程学院第一届程序设计竞赛复赛试题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试题](https://img.taocdn.com/s3/m/a152661755270722192ef75d.png)
考试时间:5小时(9:00~14:00)分数分布:共8题,满分800分。
文件命名:程序文件名为:T题号。
例如:若用C语言,第二题应提交:T2T2..C【试题一】灾区已经非常困难,灾民需要帐篷、衣物、食品和血浆。
可通往灾区的道路到处都是塌方,70%以上的路面损坏,桥梁全部被毁。
中国空军立即启动应急预案,展开史上最大强度非作战空运行动,准备向灾区空投急需物资。
由于余震不断,天气恶劣,怎样知道空投的物资是否落在某灾区的区域内?经过空中观测,多数灾区为一圆形,空投的物资落在P(Xj,Yj)点。
你能否给出一个正确判断?【标准输入】第1行:N M(N为灾区数,M为空投的物资数)接下有N行:Xi0Yi0Ri(Xi0,Yi0)为圆心坐标,Ri为圆半径i=1,2,….,N 接下有M行:Xj Yij(Xj,Yj)为空投物资的坐标j=1,2,….,M)【标准输出】输出有M行,每一行输出YES(若物资落在某个圆上或圆内,输出YES或NO否则输出NO)【约束条件】(1)1≤N≤32≤M≤10(2)Ri是一个正整数Ri<=50i=1,2,….,N(3)所有的圆心坐标和物资的坐标均为整数范围均在[-100,100]内(4)时间限制:1000MS【样例】标准输入标准输出23 0020-703050 1010-3060 3030YES YES NO据不完全统计,受地震影响,四川大部分灾区通信陷入瘫痪,数千个基站因断电、传输中断等原因退出服务,目前总公司已紧急部署对受灾地区进行通信抢修。
按照应急通信保障预案,必须尽快、付出代价最小,效率更高来全力恢复通信。
由于四川大部分灾区都处于山区,有很多基站之间不能直接建立通信。
现已知建立各基站之间直接通信的代价,问如何建立总代价最小的通信网,使得任意两个基站之间都能通信?【标准输入】第1行:N M(N为基站数M为能直接建立通信关系数)接下有M行:I J P(每行有三个数。
I J为基站的编号P为基站I与基站之间直接通信的代价)【标准输出】T(建立通信网的最小代价数)【约束条件】(1)2≤N≤10010≤M≤1000(2)0<P≤1000P为正整数(3)时间限制:1000MS【样例】标准输入标准输出57280121601330142023200345035805470密码破译某组织欲破获一个外星人的密码,密码由一定长度的字串组成。
ACM第一期训练题解题报告
![ACM第一期训练题解题报告](https://img.taocdn.com/s3/m/7424da71a26925c52cc5bfa2.png)
第一期训练题解题报告(1013、1016、1017)曾志平解题报告,就是将自己AC了的题的算法用文字/公式描述出来,并附上代码。
养成撰写解题报告的习惯,有利于加深自己对所用算法的理解和记忆,并且可以帮助后来者更快的学习ACM。
以下是第一期训练题中的思考题的解题报告。
HDU1013解题报告:题意理解:将一个正整数的各数位上数字相加,直到和为个位数为止。
注意,题目没有指定正整数的取值范围,所以可能会很大,位数可达500.算法思路:1.用char number[N]字符数据保存整数,N取个足够大的值,比如500;2.将字符串数组按元素进行求和,ASCII码的计算公式为ans +=number[i] – 48;3.如果计算出来的ans大于10,则将ans转换为字符串,转到第二步;4.否则,输出ans。
代码:int main(){char a[1000];int i, ans;while(scanf("%s", a) && a[0]!='0'){i=ans=0;while(1){while(a[i]!='\0')ans += a[i++] - 48;if(ans>9){sprintf(a, "%d", ans);i = ans = 0;}else break;}printf("%d\n", ans);}return 0;}HDU1016解题报告:题意理解:给你一个有n个节点的圆环,将数字1~n分别填入n 个节点中,要求任意两个相邻节点中的数字的和为素数。
题目指定了n的范围为0<n<20;算法思路:使用回溯法的最基本形式1.将1放入第一个节点(题目要求),进入下一个节点;2.递归:按顺序将2~n中的可用数字m放入当前节点(用for循环),如m加前一个节点中的数字为素数,则进入下一个节点,递归重复本步;若所有可用数字和前一个节点中的数字的和都不为素数,则返回递归的上一层;3.若当前节点是最后一个节点,且最后剩下的数字m和前一个节点中的数字的和,以及m+1都为素数,则从1开始依次输出各节点中的数字;否则,返回上一层递归,回到步骤2;4.直到所有的可能性都测试过了,算法终止。
ACM选拔测试题(学生版)
![ACM选拔测试题(学生版)](https://img.taocdn.com/s3/m/a325b364581b6bd97e19ea38.png)
----------------------------精品word 文档 值得下载 值得拥有---------------------------------------------- 1. 座位调整问题问题题目描述:公司办公区里到处摆放着各种各样的零食。
人力资源部的调研发现,员工如果可以在自己喜欢的美食旁边工作,工作效率会大大提高。
因此,公司决定进行一次员工座位的大调整。
调整的方法如下:1 . 首先将办公区按照各种零食的摆放分成 N 个不同的区域。
(例如:可乐区,饼干区,牛奶区等等)。
2 . 每个员工对不同的零食区域有不同的喜好程度(喜好程度度的范围为 1 — 100 的整数, 喜好程度越大表示该员工越希望被调整到相应的零食区域)。
3 . 由于每个零食区域可以容纳的员工数量有限,人力资源部希望找到一个最优的调整方案令到总的喜好程度最大。
数据输入:第一行包含两个整数 N , M ,( 1<=N , M<=300 )。
分别表示 N 个区域和 M 个员工。
第二行是 N 个整数构成的数列 a ,其中 a[i] 表示第 i 个区域可以容纳的员工数, (1<=a[i]<=M , a[1]+a[2]+..+a[N]=M) 。
紧接着是一个 M*N 的矩阵 P , P ( i , j )表示第 i 个员工对第 j 个区域的喜好度。
答案输出:对于每个测试数据,输出可以达到的最大的喜好程度。
测试数据:2. 投资问题问题描述:假设有m 元钱,n 项投资,函数()i f x 表示将x 元投入第i 个项目所产生的效益;问如何分配这m 元钱,使得投资的总效益达到最大?(C/C++程序实现)测试数据:5万元钱,4个项目,效益函数如下表所示测试要求:1. 时间2个小时,用C或C++编写程序;2. 可以携带C语言或C++方面的书;----------------------------精品word文档值得下载值得拥有----------------------------------------------。
ACM大赛训练题
![ACM大赛训练题](https://img.taocdn.com/s3/m/f877b321dd36a32d737581cd.png)
第一题:大整数一个k(1<=k<=80)位的十进制正整数n,我们称其为大整数。
现在的问题是,请设计一个程序,对于给出的某一个大整数n,找满足条件p^3+p^2+3p<=n的p的最大值。
例如输入为:10000 00000 00000 10000 00000 00000 30000 00000 00000 1输出为:10000 00000 00000 0=======================================================================第二题:王伯买鱼王伯退休后开始养鱼,他一早起来就赶去动物公园,发现这个世界的鱼还真不少,五光十色色彩斑斓。
大的、小的,什么都有。
这些鱼实在是太美了,买的人越来越多,湖里的鱼越来越少。
没有美丽的鱼,哪来美丽的湖?于是动物公园不得不规定,对于每种鱼,每个人最多只能买一条。
并且有些鱼是不能一起买的,因为他们之间会互相争斗吞食。
王伯想买尽可能多的于,但很遗憾,他的资金有限。
王伯冥思苦想,不知如何是好。
请编写一个程序帮助他。
如果有多个方案都能买尽可能多的鱼,选择所花资金最多的一个。
输入格式:从文本文件读入输入数据,输入文件的第一行是两个正整数M(M<=1000), N(N<=30),分别表示王伯的资金和鱼的种类。
一下N行,每行两个正整数S(1<=S<=N)、T,分别表示某种鱼的编号以及该鱼的价格。
接着,每行有两个正整数P、Q。
当P、Q均大于0时,表示P、Q不能共处;当p、Q均为0时,表示输入文件的结束。
输出格式:输出文件的第一行为两个正整数X、Y,分别表示所买鱼的条数和总花费。
以下X行,每行一个正整数,表示所买鱼的编号。
编号按照升序排列输出。
如果题目有多个解,只需输出其中的一个。
例如,输入为:170 71 702 503 304 405 406 307 201 41 73 43 55 76 70 0对应的输出为:4 1602456==================================================================。
acm选拔试题及答案
![acm选拔试题及答案](https://img.taocdn.com/s3/m/32728f89846a561252d380eb6294dd88d0d23de4.png)
acm选拔试题及答案# acm选拔试题及答案1. 问题描述:编写一个程序,计算给定整数序列中,连续子序列的最大和。
2. 输入格式:第一行包含一个整数 \( n \),表示序列的长度。
第二行包含 \( n \) 个整数,表示序列中的元素。
3. 输出格式:输出一个整数,表示连续子序列的最大和。
4. 示例:输入:```51 -234 -1```输出:```6```5. 问题分析:这个问题可以通过动态规划的方法来解决。
定义一个数组 `dp[i]` 来表示以第 `i` 个元素结尾的连续子序列的最大和。
6. 算法逻辑:- 初始化 `dp[0]` 为序列的第一个元素。
- 对于每个 `i`(从 1 到 `n-1`),`dp[i]` 可以通过 `dp[i-1] + nums[i]` 来更新,如果 `dp[i-1]` 是负数,则 `dp[i]` 应该等于`nums[i]`。
- 遍历序列,更新 `dp` 数组,同时记录最大和。
7. 代码实现:```pythondef max_subarray_sum(nums):n = len(nums)max_sum = nums[0]current_sum = nums[0]for i in range(1, n):current_sum = max(nums[i], current_sum + nums[i]) max_sum = max(max_sum, current_sum)return max_sum```8. 测试用例:- 输入:`[-2, 1, -3, 4, -1, 2, 1, -5, 4]`- 输出:`6`9. 答案解析:- 该测试用例中,连续子序列 `[4, -1, 2, 1]` 的和为 `6`,是所有可能子序列中的最大值。
10. 注意事项:- 考虑边界条件,如序列中所有元素都是负数的情况。
- 优化算法以处理大数据量的情况。
11. 附加说明:- 该问题也可以通过分治法或贪心算法来解决,但动态规划提供了一个更简洁且易于理解的解决方案。
ACM大赛原题目
![ACM大赛原题目](https://img.taocdn.com/s3/m/0f260fbdc77da26925c5b0e1.png)
一Network of SchoolsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 4526 Accepted: 1776 DescriptionA number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes software (the “receiving schools”). Note that ifB is in the distribution list of school A, then A does not necessarily appear in the list of school BYou are to write a program that computes the minimal number of schools that must receive a copy of the new software in order for the software to reach all schools in the network according to the agreement (Subtask A). As a further task, we want to ensure that by sending the copy of new software to an arbitrary school, this software will reach all schools in the network. To achieve this goal we may have to extend the lists of receivers by new members. Compute the minimal number of extensions that have to be made so that whatever school we send the new software to, it will reach all other schools (Subtask B). One extension means introducing one new member into the list of receivers of one school.InputThe first line contains an integer N: the number of schools in the network (2 <= N <= 100). The schools are identified by the first N positive integers. Each of the next N lines describes a list of receivers. The line i+1 contains the identifiers of the receivers of school i. Each list ends with a 0. An empty list contains a 0 alone in the line.OutputYour program should write two lines to the standard output. The first line should contain one positive integer: the solution of subtask A. The second line should contain the solution of subtask B.Sample Input52 43 04 5 01 0Sample Output12二Remmarguts' DateTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 10811 Accepted: 2944 Description"Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story."Prince Remmarguts lives in his kingdom UDF – United Delta of Freedom. One day their neighboring country sent them Princess Uyuw on a diplomatic mission.""Erenow, the princess sent Remmarguts a letter, informing him that she would come to the hall and hold commercial talks with UDF if and only if the prince go and meet her via the K-th shortest path. (in fact, Uyuw does not want to come at all)"Being interested in the trade development and such a lovely girl, Prince Remmarguts really became enamored. He needs you - the prime minister's help!DETAILS: UDF's capital consists of N stations. The hall is numbered S, while the station numbered T denotes prince' current place. M muddy directed sideways connect some of the stations. Remmarguts' path to welcome the princess might include the same station twice or more than twice, even it is the station with number S or T. Different paths with same length will be considered disparate.InputThe first line contains two integer numbers N and M (1 <= N <= 1000, 0 <= M <= 100000). Stations are numbered from 1 to N. Each of the following M lines contains three integer numbers A, B and T (1 <= A, B <= N, 1 <= T <= 100). It shows that there is a directed sideway from A-th station to B-th station with time T.The last line consists of three integer numbers S, T and K (1 <= S, T <= N, 1 <= K <= 1000).OutputA single line consisting of a single integer number: the length (time required) to welcome Princess Uyuw using the K-th shortest path. If K-th shortest path does not exist, you should output "-1" (without quotes) instead.Sample Input2 21 2 52 1 41 2 2Sample Output14三ChessboardTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 7406 Accepted: 2306 DescriptionAlice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy to bob, so she makes some holes on the board (as shown in the figure below).We call a grid, which doesn’t contain a hole, a normal grid. Bob has to follow the rules below:1. Any normal grid should be covered with exactly one card.2. One card should cover exactly 2 normal adjacent grids.Some examples are given in the figures below:A VALID solution.An invalid solution, because the hole of red color is covered with a card.An invalid solution, because there exists a grid, which is not covered.Your task is to help Bob to decide whether or not the chessboard can be covered according to the rules above.InputThere are 3 integers in the first line: m, n, k (0 < m, n <= 32, 0 <= K < m * n), the number of rows, column and holes. In the next k lines, there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th column.OutputIf the board can be covered, output "YES". Otherwise, output "NO".Sample Input4 3 22 13 3Sample OutputYES四RSATime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 2583 Accepted: 490DescriptionRSA is the best-known public key encryption algorithm. In this algorithm each participant has a private key that is shared with no one else and a public key which is published so everyone knows it. To send a secure message to this participant, you encrypt the message using the widely known public key; the participant then decrypts the messages using his or her private key. Here is the procedure of RSA:First, choose two different large prime numbers P and Q, and multiply them to get N (= P * Q).Second, select a positive integer E (0 < E < N) as the encryption key such that E and T= (P - 1) * (Q - 1) are relatively prime.Third, compute the decryption key D such that 0 <= D < T and (E * D) mod T = 1. Here D is a multiplicative inverse of E, modulo T.Now the public key is constructed by the pair {E, N}, and the private key is {D, N}. P and Q can be discarded.Encryption is defined by C = (M ^ E) mod N, and decryption is defined by M = (C ^ D) mod N, here M, which is a non-negative integer and smaller than N, is the plaintext message and C is the resulting ciphertext.To illustrate this idea, let’s see the following example:We choose P = 37, Q = 23, So N = P * Q = 851, and T = 792. If we choose E = 5, D will be 317 ((5 * 317) mod 792 = 1). So the public key is {5, 851}, and the privatekey is {317, 851}. For a given plaintext M = 7, we can get the ciphertext C = (7 ^ 5) mod 851 = 638.As we have known,for properly choosen very large P and Q, it will take thousands of years to break a key, but for small ones, it is another matter.Now you are given the ciphertext C and public key {E, N}, can you find the plaintext M?InputThe input will contain several test cases. Each test case contains three positive integers C, E, N (0 < C < N, 0 < E < N, 0 < N < 2 ^ 62).OutputOutput the plaintext M in a single line.Sample Input638 5 851Sample Output7五A New Operating SystemTime Limit: 20000MS Memory Limit: 65536KTotal Submissions: 669 Accepted: 49Case Time Limit: 5000MSDescriptionMay is a lovely girl. Due to her filial piety, she wants to give a present on hermother's birthday. Because both her parents are the top programmer in the world, she decided to design a new program, a special program that is an Operating System! With the help of her excellent programming skill, May has already finished the kernel of the new OS. And the birthday is coming, she is afraid that time is not enough to finish the entire project in time. As her best net-pal, it's your duty to help her.This is a multitask OS, processes run at the same time. There are following command in the OS:CreateProcess(PID,Memory,Priority)A new process is created with the process identification PID and memory size, and a priority. The priority in this command is called outer priority of a process.AddMessage(PID,Priority)That means, add a new message to the message queue of process PID, with the priority of Priority. The message with higher Priority will run earlier that lower ones. The Priority is called inner priority.RunFind out the message with biggest HP. HP is defined as the product of the inner priority of a message and the corresponding process priority. If two or more messages have the same HP, the one with smallest PID will run first. Print the information "Run: HP" to the output file, HP will be replaced by the message HP you found, or print "Empty" instead if the message queue is empty. Finally remove this message if exist.ChangePriority(PID,NewValue)Change the outer priority of process PID to NewValue.GetMemory(PID,Memory)Process PID memory increases the amount of Memory.FreeMemory(PID,Memory)Process PID memory decreases the amount of Memory.RunProcess(PID)Similar with Run command. Find out the message in the process PID message queue, print the information "Run Process: Priority" to the output file, Priority will be replaced by the message priority you found, or print "Empty" instead if the messagequeue is empty. Finally remove this message if exist.CloseMaxMemoryFind out the process that used the largest number of memory and close it if exists (if tie, the one with smallest PID should be release first), or print "Empty" instead.CloseProcess(PID)Close the process with the identification of PID.Whenever a process' memory is less than or equal to 0, it will be close automatically. In any of the above commands except the first one, if the PID doesn't exist, please print an "Error" to the output. For the first command, if the PID is already exist, print an "Error" and ignore this command.InputFirst line in the input is an integer number N (1 <= N <= 100000), which represents the number of commands. The next N lines, each gives a command described above. Any number given in the input file will be non-negative integer and will not be more than 1000000000.OutputThe output format has been described above.Sample Input11CloseMaxMemoryCreateProcess(1,100,1)CreateProcess(2,200,1)CreateProcess(3,300,1)AddMessage(1,9)AddMessage(2,19)AddMessage(1,10)GetMemory(2,999)CloseMaxMemoryRunRunProcess(1)Sample OutputEmptyRun: 10Run Process: 9六A New Kind of ChessTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 245 Accepted: 42DescriptionPrince Remmarguts met Uyuw successfully in our previous story, and after that Princess Uyuw introduced a new kind of chess to Remmarguts named Nixgnauhc. The only chessman allowed in it was a special type of Knight.The chessboard is of (N + 1) * (M + 1). Each of the rows and columns are numbered as the following graph:Here N + 1 = 5 + 1 is the number of rows and M + 1 = 4 + 1 is the number of columns. We are also given two integer numbers P and Q, and told that at the beginning of the game, the blocks of (x, y) - (row number, column number) - where x <= P and y <= Q are already taken up by Knight.During the game, we can choose a single Knight to move, and the only allowed movements for Knight at (x, y) is to (x + a, y + b) or to (x + c, y + d). But during the movement, the position it goes must be on the chessboard and NOT be taken up by another Knight. Our purpose is to move that chessman to the final end (N, M). (The description above means that once you choose a chessman, you can only move that chessman in the following steps)Meanwhile, we suppose 3 <= N, M <= 100000, 0 <= P < N, 0 <= Q < M, 1<= a, b, c, d. Princess Uyuw wanted to know the number of essentially different games. Two games are called “different” if and only if we choose the different chessman at the beginning or perform a different movement at some time.WARNING: Even if a = c, b = d, we also call (+a, +b) and (+c, +d) DIFFERENT movements!InputYou should read the number of test cases Z in the first line – Z <= 100.Each of the following lines denotes a single test case, consisting of 8 integers N, M, P, Q, a, b, c, and d. The meanings of such integers are described above.OutputOutput one line per test case, showing the total possibilities of games. We guarantee this number is less than 10^500.Sample Input23 3 0 0 1 1 1 15 4 2 1 1 1 2 1Sample Output87七An Easy ProblemTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 6197 Accepted: 3631 DescriptionAs we known, data stored in the computers is in binary form. The problem we discuss now is about the positive integers and its binary form.Given a positive integer I, you task is to find out an integer J, which is the minimum integer greater than I, and the number of '1's in whose binary form is the same as that in the binary form of I.For example, if "78" is given, we can write out its binary form, "1001110". This binary form has 4 '1's. The minimum integer, which is greater than "1001110" and also contains 4 '1's, is "1010011", i.e. "83", so you should output "83".InputOne integer per line, which is I (1 <= I <= 1000000).A line containing a number "0" terminates input, and this line need not be processed. OutputOne integer per line, which is J.Sample Input123478Sample Output245883八Uyuw's ConcertTime Limit: 6000MS Memory Limit: 65536KTotal Submissions: 3177 Accepted: 1240 DescriptionPrince Remmarguts solved the CHESS puzzle successfully. As an award, Uyuw planned to hold a concert in a huge piazza named after its great designer Ihsnayish.The piazza in UDF - United Delta of Freedom’s downtown was a square of [0, 10000] * [0, 10000]. Some basket chairs had been standing there for years, but in a terrible mess. Look at the following graph.In this case we have three chairs, and the audiences face the direction as what arrows have pointed out. The chairs were old-aged and too heavy to be moved. Princess Remmarguts told the piazza's current owner Mr. UW, to build a large stage inside it. The stage must be as large as possible, but he should also make sure the audience in every position of every chair would be able to see the stage without turning aside (that means the stage is in the forward direction of their own).To make it simple, the stage could be set highly enough to make sure even thousands of chairs were in front of you, as long as you were facing the stage, you would be able to see the singer / pianist – Uyuw.Being a mad idolater, can you tell them the maximal size of the stage?InputIn the first line, there's a single non-negative integer N (N <= 20000), denoting the number of basket chairs. Each of the following lines contains four floating numbers x1, y1, x2, y2, which means there’s a basket chair on the line segment of (x1, y1) –(x2, y2), and facing to its LEFT (That a point (x, y) is at the LEFT side of this segment means that (x – x1) * (y – y2) – (x – x2) * (y – y1) >= 0).OutputOutput a single floating number, rounded to 1 digit after the decimal point. This is the maximal area of the stage.Sample Input310000 10000 0 500010000 5000 5000 100000 5000 5000 0Sample Output54166666.7九Knight MovesTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 15129 Accepted: 6765 DescriptionBackgroundMr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can move knights from one position to another so fast. Can you beat him?The ProblemYour task is to write a program to calculate the minimum number of moves needed for a knight to reach one point from another, so that you have the chance to be faster than Somurolov.For people not familiar with chess, the possible knight moves are shown in Figure 1.InputThe input begins with the number n of scenarios on a single line by itself.Next follow n scenarios. Each scenario consists of three lines containing integer numbers. The first line specifies the length l of a side of the chess board (4 <= l <= 300). The entire board has size l * l. The second and third line contain pair of integers {0, ..., l-1}*{0, ..., l-1} specifying the starting and ending position of the knight on the board. The integers are separated by a single blank. You can assume that the positions are valid positions on the chess board of that scenario.OutputFor each scenario of the input you have to calculate the minimal amount of knight moves which are necessary to move from the starting point to the ending point. If starting point and ending point are equal,distance is zero. The distance must be written on a single line.Sample Input380 07 01000 030 50101 11 1十Equal Sum PartitionsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 297 Accepted: 214DescriptionAn equal sum partition of a sequence of numbers is a grouping of the numbers (in the same order as the original sequence) in such a way that each group has the same sum. For example, the sequence:2 5 13 3 7may be grouped as:(2 5) (1 3 3) (7)to yield an equal sum of 7.Note: The partition that puts all the numbers in a single group is an equal sum partition with the sum equal to the sum of all the numbers in the sequence.For this problem, you will write a program that takes as input a sequence of positive integers and returns the smallest sum for an equal sum partition of the sequence.InputThe first line of input contains a sin gle integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. The first line of each data set contains the data set number, followed by a space, followed bya decimal integer M, (1 ≤ M ≤ 10000), giving the total number of integers in the sequence. The remaining line(s) in the dataset consist of the values, 10 per line,separated by a single space. The last line in the dataset may contain less than 10 values.OutputFor each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the smallest sum for an equal sum partition of the sequence.Sample Input31 62 5 13 3 72 61 2 3 4 5 63 201 12 1 1 2 1 1 2 11 2 1 1 2 1 1 2 1 1Sample Output1 72 213 2如果有想要答案的朋友,请给我留言!。
西电ACM校队选拔测试题
![西电ACM校队选拔测试题](https://img.taocdn.com/s3/m/0a26e9dcda38376baf1fae53.png)
西电ACM校队2013年选拔笔试姓名:学号:USACO进度:联系方式:一、综合题(8分×8)(1)1~10000以内,有多少个数字只包含1,2,3?有多少个数字只包含1,2,3且是3的倍数?(2)现在有一个天平,想称出来1~40之间的所有整数重量,最少需要几个砝码,他们的重量分别是多少?(3)现在有{1,2,3,4,5,……100},共100个数字,每次可以取其中连续的若干个数字(最多5个,最少1个),比如取了2~6,则其变成了{1,7~100},现在两个人轮流取,取走最后一个数字的人输,则,先手如何决策,才能使得自己无论如何都不会输?(4)三个小伙子同时爱上了一个姑娘,为了决定他们谁能娶这个姑娘,他们决定用手枪进行一次决斗。
小李的命中率是30%,小黄比他好些,命中率是50%,最出色的枪手是小林,他从不失误,命中率是100%。
由于这个显而易见的事实,为公平起见,他们决定按这样的顺序:小李先开枪,小黄第二,小林最后。
然后这样循环,直到他们只剩下一个人。
那么这三个人中谁活下来的机会最大呢?他们都应该采取什么样的策略?(5)魔术师约翰喜欢玩一个魔术,他从52张扑克牌中随机抽取27张牌,然后选择其中一张扔掉,把剩下的26张牌给他的助手看,美丽的助手便会立即猜到他扔掉的是哪一张牌,试简述其中的玄妙所在。
(6)简述你所熟悉的排序算法,并任选一种把核心代码写在下面。
(7)简述你对判断一个数字是否是素数的算法的认识,讲讲你所了解的算法。
(8)ZYF最喜欢挖坑埋东西了!他最近想挖个正方形截面的坑把N个边长为1的小正方形薄片埋了,为了追求美感他把这些薄片平铺在坑底,保证薄片之间不重叠、覆盖。
那么他至少得挖边长为多少的正方形坑呢?对于N=4,5,6给出你的答案,并画图。
(9)罗列你所知道的ACM算法,并给出分类框架,比如算法分为图论,数论,组合数学……,其中,图论包括最小生成树……。
(10)如果你寒假做了USACO,令你收获最大的是哪一道题目,试描述。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Your job is to calculate the total score for a given user.InputThe first line contains an integer np(1≤np≤300) which is the number of problems in Online Judge. The second line contains np integers representing the number of users who have solved this problem from problem 1000 to problem 1000+np-1.The third line contains an integers t(t≤10), which is the number of test cases.Each test case begins with an integer n, which is the number of problems the user has solved. Then it is followed by n distinct integers which are the problem ids. Problem id is labeled from 1000.OutputFor each test case, print the total score he can get on a single line.Sample Input10100 10 11 3 45 7 34 200 70 142 1000 10012 1001 10023 1000 1007 1008Sample Output121872.求值Time Limit: 1000MS Memory Limit: 10000K Description给出N个整数X1,X2,X3,……,Xn,将这N个数从小到大排序为A1,A2,A3,……,An,记数列A1,A2,A3,……,An的奇数项之和为P,偶数项之和为Q,令T=|P-Q|,求出T的值。
Input输入文件的第1行为整数N(1≤N≤50000)。
接下来的N行每行有一个整数,按顺序给出X1,X2,X3,……,Xn的值(|Xi|<=1000)Output输出整数T的值。
Sample Input3132Sample Output23.软件工程Time Limit: 1000MS Memory Limit: 10000K DescriptionMerlin的软件工程老师Max布置了开发一个软件的大作业。
由于这是一个大型软件,所以单靠Merlin 一个人不可能在预定时间内做完,必须与其他人合作。
由于大家都要做这个作业,所以Merlin理所当然找他的同班同学,但是同班同学的能力参差不起。
全班都很明确,这个工程可以分为n个不同的部分,每个部分都是独立,并且每个人都有一定的能力完成其中一个部分。
Merlin认为,自己应该去做项目经理的职位,把n个部分分配给若干个人,不同的部分可以分配给一个人或者多个人,但是一个部分只能分配给一个人。
Merlin的人缘很好,同学们都愿意与他合作。
但是,每个人每个部分能够得到的分数是不同的,Merlin 希望给每个人每个部分能够得到的分数做一个估算(百分制),而能够得到的分数就是项目的个人部分的总和,最后求出平均值。
即最后分数=每个部分的分数之和/n。
面对众多的分数,Merlin害怕了,而且Merlin很懒,自己不想去做其中任何的一个部分,请你编写一个程序,帮组Merlin求出可以得到的最高分。
Input第1行是一个正整数n(n≤1000),表示项目可以划分为n部分。
第2行是一个正整数m(m≤1000),表示全班一共有m个同学(不包括Merlin)。
然后是m行n列的正整数,第i行j列正整数k(k≤100),表示同学i可以在项目中的第j部分获得分数k。
Output只有一个实数。
Merlin能够得到的最大分数,结果保留两位小数。
Sample Input5590 90 90 85 9090 85 90 90 8590 90 85 90 9090 90 90 90 8585 90 85 90 90Sample Output90.004.脱离地牢Time Limit: 1000MS Memory Limit: 10000K Description在一个神秘的国度里,年轻的王子Paris与美丽的公主Helen在一起过着幸福的生活。
他们都随身带有一块带磁性的阴阳魔法石,身居地狱的魔王Satan早就想得到这两块石头了,只要把它们溶化,Satan就能吸收其精华大增自己的魔力。
于是有一天他趁二人不留意,吧他们带到了自己的地牢,分别困在了不同的地方。
然后Satan念起了咒语,准备炼狱,届时二人都将葬身于这地牢里。
危险!Paris与Helen都知道了Satan的意图,他们怎样才能打败魔王,脱离地牢呢?Paris想起了父王临终前留给他的备忘本,原来他早已料到了Satan的野心,他告诉Paris只要把两块魔法石合在一起,念起咒语,它们便会放出无限的光亮,杀死魔王,脱离地牢,而且本子上还附下了地牢的地图,Paris从中了解到了Helen的位置所在。
于是他决定首先要找到Helen,但是他发现这个地牢很奇怪,它会增强二人魔法石所带磁力的大小,而且会改变磁力的方向。
这就是说,每当Paris向南走一步,Helen有可能会被石头吸引向北走一步。
而这个地狱布满了岩石与岩浆,Paris必须十分小心,不仅他不能走到岩石或岩浆上,而且由于他行走一步,Helen的位置也会改变,如果Helen碰到岩石上,那么她将停留在原地,但如果Helen移动到了岩浆上,那么她将死去,Paris就找不到她了。
Paris仔细分析了地图,他找出了一条最快的行走方案,最终与Helen相聚。
他们一起念出了咒语“@^&#…%@%&$”,轰隆一声,地牢塌陷了,他们又重见光明……Input输入数据第1行为两个整数n,m(3≤n,m≤20),表示地牢的大小,n行m列。
接下来n行,每行m个字符,描述了地牢的地图,“.”代表通路,“#”代表岩石,“!”代表岩浆。
输入保证地牢是封闭的,即四周均是岩石或岩浆。
“P”和“H”分别代表Paris和Helen的位置。
接下来有4个字符“N”(北),“S”(南),“W”(西),“E”(东)的排列,表示Paris分别向N、S、W、E方向走时Helen受磁石磁力影响的移动方向。
Output输出文件只有1行,如果Paris能找到Helen,输出一个整数d,为Paris最少需要行走的步数;如果Paris在255步之后仍找不到Helen,则输出“Impossible”。
注意相遇是指Paris与Helen最终到达同一个格子,或者二人在相邻两格移动后碰在了一起,而后者的步数算他们移动的步数。
Sample Input5 5######H..##.!.##.#P######WNSESample Output55.最大公共子串Time Limit: 1000MS Memory Limit: 10000K Description从一个给定的串中删去(不一定连续地删去)0个或0个以上的字符,剩下的字符按原来顺序组成的串是该串的子串。
例如:“”,“a”,“xb”,“aaa”,“bbb”,“xabb”,“xaaabbb”都是串“xaaabbb”的子串。
(例子中的串不包含引号。
)编程求N个非空串的最长公共子串的长度。
限制:2≤N≤100;N个串中的字符只会是数字0,1,……,9或小写英文字母a,b,……,z;每个串非空且最多含100个字符:N个串的长度的乘积不会超过30000。
Input文件第1行是一个整数T,表示测试数据的个数(1≤T≤10)。
接下来有T组测试数据。
各组测试数据的第1行是一个整数Ni,表示第i组数据中串的个数。
各组测试数据的第2至N+1行中,每行一个串,串中不会有空格,但行首和行末可能有空格,这些空格当然不算作串的一部分。
Output输出T行,每行一个数,第i行的数表示第i组测试数据中Ni个非空串的最长公共子串的长度。
Sample Input13abbccdSample Output6.Stone GameTime Limit: 1000MS Memory Limit: 10000KDescriptionDennis and Joyce love to collect stones and play games with them. Up till now they have collected Na white stones and Nb black stones, and they are going to play a new game. The rules of the game is as follows:(1) All the stones are put into a pocket initially, so that each stone has equal possibility to be picked up, and each time a stone is picked up randomly.(2) The two players take turns to pick up a stone, if the stone is black, the current player should put it back to the pocket; otherwise the player could keep the stone.(3) Whoever picks up the last white stone wins the game.Now they haven’t decided who plays first. To make a better decision, Dennis have asked you, an excellent programmer, to calculate the winning possibility for the first player. Since they are going to start playing soon, you must finish the job as quickly as possible, Come on!InputThe first line is a single number n, the number of test cases followed. In the next n lines, each line contains two non-negative integers, Na and N b,(0≤Na, Nb≤64).OutputFor each test case, output a real number indicating the possibility for the first player to win. The answer should be rounded to 6 digits after the decimal point. No extra spaces are allowed.Sample Input31 00 13 10Sample Output1.0000000.0000000.5002827.速配游戏Time Limit: 1000MS Memory Limit: 10000K Description有一个速配电视节目。