当前位置:文档之家› 重庆理工大学程序设计大赛选拔试题

重庆理工大学程序设计大赛选拔试题

程序提交方法,务必看清楚步骤!1、在编写源代码时,读写的文件均不应有目录信息,而必须用“文件名.扩展名”的形式。

例如:fp=fopen(“sentence.in”,”r”)或fp=fopen(“estdout.pc2”,”w”)2、双击桌面上的“程序设计大赛”快捷键,弹出如下对话框,在Name和password编辑框均输入:team+对号,如对号为1的,用户名和密码均为team13、在输入Name和password后,点击login登录,出现如下对话框:在problem下拉列表框选择自己要提交哪个问题的源代码→在language下拉列表框选择自己编写程序所用的语言→在Main file下拉列表框选择自己源代码文件→点击Test按钮,若无错误,则进行下一步→点击submit按钮提交!本次测试的题目名字和源程序文件名一致,源程序的扩展名若为cpp,则language 应选择Microsoft C++,源程序的扩展名若为java,则language应选择Java.提交后系统会给出一个结果例如:Yes正确(简单称ac)No-Compilition Error 为编译错误简单称(ce)No-Run-time Error 运行中意外终止(RE)(也有可能是格式错误)No-time-limit Exceeded程序运行超时(TLE)No-Wrong Answer 答案错误No-Excessive Out put 程序输出结果超出pc^2所能检测的范围No-Output Format Error 格式错误No-Other-Contact Staff 其他未知错误重庆理工大学第五届程序设计大赛试题试题1:【反转单词】给你一些英文句子,请将这些句子中的每个英语单词反转,然后再将其输出.这里的英语单词仅由大小写英文字母组成.【输入】输入文件名“sentence.in”多个英文句子,每句占一行,且每句不超过80个字符.【输出】输出文件名“estdout.pc2”按题目要求输出。

程序运行后结果示例:【样例输入】Helloworld!Happyprogramming,happylife!【样例输出】olleHdlrow!yppaHgnimmargorp,yppahefil!试题2:【全排列问题】大家知道,给出正整数n,则1到n这n个数可以构成n!种排列,把这些排列按照从小到大的顺序(字典顺序)列出,如n=3时,列出1 2 3,1 3 2,2 1 3,2 3 1,3 1 2,3 2 1六个排列。

要求给出某个排列,求出这个排列的下k个排列,如果遇到最后一个排列,则下1排列为第1个排列,即排列1 2 3…n。

比如:n = 3,k=2 给出排列2 3 1,则它的下1个排列为3 1 2,下2个排列为3 2 1,因此答案为3 2 1。

【输入】输入文件名“permutation.in”第一行是一个正整数m,表示测试数据的个数,下面是m组测试数据,每组测试数据第一行是2个正整数n( 1 <= n < 1024 )和k(1<=k<=64),第二行有n个正整数,是1,2 …n的一个排列。

【输出】输出文件名“estdout.pc2”对于每组输入数据,输出一行,n个数,中间用空格隔开,表示输入排列的下k个排列。

程序运行后结果示例:【样例输入】33 12 3 13 13 2 110 21 2 3 4 5 6 7 8 9 10【样例输出】3 1 21 2 31 2 3 4 5 6 7 9 8 10试题3:【猜数游戏】猜数游戏在XXX国非常流行,游戏过程大概是这样的……一个裁判,三个路人,路人足够聪明。

每次裁判会选出三个正整数,其中某两个相加等于第三个然后分别把这数写在三个路人的脸上也就是说,每个路人都知道另外两个路人的数字但不知道自己脸上的数是什么游戏开始,裁判每一轮都会问他们三个能否猜出自己脸上是什么,为了体现游戏的公正性,路人们必须同时给出回答。

直到有一个路人猜出自己的数时游戏停止那么,如果告诉你这三个数a,b,c,为了证明你比路人厉害,你能预测出游戏会在第几轮停止吗?【输入】输入文件名“guess.in”每行三个正整数a,b,c,(1<=a,b,c<=1000000)其中一个是另外两个的和以0 0 0结束。

【输出】输出文件名“estdout.pc2”每行输出一个数,表示游戏在第几轮结束,从1开始计数。

程序运行后结果示例:【样例输入】1 1 21 2 33 2 1123 5 1280 0 0【样例输出】12228试题4:【青蛙的约会】两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。

它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。

可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。

不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。

但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。

为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。

我们把这两只青蛙分别叫做青蛙A和青蛙B,并且规定纬度线上东经0度处为原点,由东往西为正方向,单位长度1米,这样我们就得到了一条首尾相接的数轴。

设青蛙A的出发点坐标是x,青蛙B的出发点坐标是y。

青蛙A一次能跳m米,青蛙B一次能跳n米,两只青蛙跳一次所花费的时间相同。

纬度线总长L米。

现在要你求出它们跳了几次以后才会碰面。

【输入】输入文件名“frog.in”输入只包括一行5个整数x,y,m,n,L,其中x≠y < 2000000000,0 < m、n < 2000000000,0 < L < 2100000000。

【输出】输出文件名“estdout.pc2”针对输入的数据如果永远不可能碰面则输出一行Impossible,如果可以碰面则输出碰面所需要的跳跃次数。

【样例输入】1 2 3 4 5【样例输出】4试题5:【拔河游戏】拔河是一种主要靠体力对抗的游戏。

人们分为两队,往相反的方向拉同一根绳子,成功将绳子拉到自己一方的队将胜。

某公司的聚会上将举行一次拔河比赛。

他们想把参与者尽可能分为实力相当的两支队伍中去。

每个人必须在基中一支队伍里,两队的人数差距不能超过一人,且两队的队员总体重应该尽可能接近。

【输入】输入文件名“war.in”第一行输入一个数M,表示以下将有M个人参加比赛,从第二行开始,每一行将有一个数字,表示一个人的体重,用1~300的数字表示。

参加聚会的人数最多为100人。

【输出】输出文件名“estdout.pc2”输出两行数据,第一行表示第一队队员的总体重,第二行表示另一支队伍的总体重(要求,先输出体重较小的队伍的总体重)【样例输入】710090200220130120110【样例输出】470500试题6:Transferable VotingThe Transferable V ote system for determining the winner of an election requires that a successful candidate obtain an absolute majority of the votes cast, even when there are more than two candidates. To achieve this goal,each voter completes his or her ballot by listing all the candidates in order of preference. Thus if there are five candidates for a single position, each voter's ballot must contain five choices, from first choice to fifth choice.In this problem you are to determine the winner, if any, of elections using the Transferable V ote system. If there are c candidates for the single position, then each voter's ballot will include c distinct choices, corresponding to identifying the voter's first place, second place, ..., and nth place selections. Invalid ballots will be discarded, but their presence will be noted. A ballot is invalid if a voter's choices are not distinct (choosing the same candidate as first and second choice isn't permitted) or if any of the choices aren't legal (that is, in the range 1 to c).For each election candidates will be assigned sequential numbers starting with 1. The maximum number of voters in this problem will be 100, and the maximum number of candidates will be 5.Table A Table B----------------------------- -------V oter First Second ThirdChoice Choice Choice1 12 42 13 2 1 3 23 3 2 1 3 2 14 3 2 1 3 2 15 1 2 3 1 2 36 2 3 1 3 17 3 2 1 3 2 18 3 1 19 3 2 1 3 2 110 1 2 3 1 2 311 1 3 2 1 3 212 2 3 1 3 1Consider a very small election. In Table A are the votes from the 12 voters for the three candidates. V oters 1 and 8 cast invalid ballots; they will not be counted. This leaves 10 valid ballots, so a winning candidate will require at least 6 votes (the least integer value greater than half the number of valid ballots) to win. Candidates 1 and 3 each have 4 first choice votes, and candidate 2 has two. There is no majority, so the candidate with the fewest first choice votes, candidate 2, is eliminated. If there had been several candidates with the fewest first choice votes, any of them, selected at random, could be selected for elimination.With candidate 2 eliminated, we advance the second and third choice candidates from those voters who voted for candidate 2 as their first choice. The result of this action is shown in Table B. Now candidate 3 has picked up 2 additional votes, giving a total of 6. This is sufficient for election. Note that if voter 12 had cast the ballot "2 1 3" then there would have been a tie between candidates 1 and 3.【Input】Input filename “voting.in”There will be one or more elections to consider. Each will begin with a line containing the number of candidates and the number of voters, c and n. Data for the last election will be followed by a line containing two zeroes.Following the first line for each election will be n additional lines each containing the choices from a single ballot. Each line will contain only c non-negative integers separated by whitespace.【Output】Output filename “estdout.pc2”For each election, print a line identifying the election number (they are numbered sequentially starting with 1). If there were any invalid ballots, print an additional line specifying the number of such. Finally, print a line indicating the winner of the election, if any, or indication of a tie; be certain to identify the candidates who are tied. Separate the output for each election by a single blank line.Sample Input3 121 2 41 3 23 2 13 2 11 2 32 3 13 2 13 1 13 2 11 2 31 3 22 3 13 121 2 41 3 23 2 13 2 11 2 32 3 13 2 13 1 13 2 11 2 31 3 22 1 34 154 3 1 24 1 2 33 14 21 32 44 1 2 33 4 2 12 43 13 2 1 43 14 21 42 33 4 1 23 2 1 44 1 3 23 2 1 44 2 1 40 0Sample OutputElection #12 bad ballot(s)Candidate 3 is elected.Election #22 bad ballot(s)The following candidates are tied: 1 3 Election #31 bad ballot(s)Candidate 3 is elected.。

相关主题