桂林电子科技大学ACM程序设计校内竞赛试题▲此套试题共8道,请根据自己实际情况尽最大努力去完成。
▲每位参赛的同学需在考试用机的工作盘上创建一个名为Exam2004的临时文件夹用以保存所有的工作文件。
上机编程调试出正确结果。
按照试题顺序把每题的运行结果、源程序和算法说明(即解题思路说明)合并到一个Word 文档。
该Word文档的文件名按如下格式命名:学号+姓名最后将该文件拷至制定的服务器上。
1、请看如下图4*4的一个网格。
你能告诉我网格中隐含了多少正方形?也许你能手工数出来,但是你能数100*100或者1000*1000的网格吗?请编写一个程序:输入:输入一个整数N(0<=N<=100),代表网格的边长输出:输出2维网格N*N中不同大小的正方形的数目S.如以上4*4网格共有正方形302、对于一个8位二进制码,它的镜像就是将它的第n位于倒数第n位交换,使它的每一位都这样交换。
例如,代表十进制数46的二进制数是00101110。
它的镜像是二进制码01110100,即十进制数116。
编写一个程序,输入一个整数N(如46),输出其镜像M(如116)。
3、给你9个整数,这9个整数分别是x的8次方至0次方的系数,请你按照多项式的一般形式合理地构造(去除不必要的)。
例如9个系数分别为0,0,0,1,22,-333,0,1,-1,你要构造并输出一行多项式: x^5+22x^4-333x^3+x-1。
要求:可以输入多行系数,再显示结果。
如输入:0 0 0 1 22 -333 0 1 -10 0 0 0 0 0 6 88 0E(输入结束标志)输出:x^5+22x^4-333x^3+x-16x^2+88x4、美国人的家族农夫John对他的奶牛继承关系非常认真。
但是他不是一个很好的记录员,他以一种二叉树的方法来记录他奶牛的继承关系。
他用字符串来记录一棵树的前序、中序遍历,而不是用图形方式来表示这棵树。
你的任务是对于给出的奶牛继承关系的前序树和中序树表示,找出它的后序树表示。
每个奶牛的名字用一个字母来代表。
输入规范第一行输入中序序列第二行输入前序序列输出规范显示后序序列实例输入In order: AEDFCHG // 中序序列输入Pre order: CBADEFGH //前序序列输入实例输出Post order: AEFDBHGC //后序输出5、数字三角形考虑右图所示的无限等边三角形网格上的点,注意到如果我们用数字将这些点从上至下、从左至右标记,某些点构成一些特定几何图形的顶点。
例如,{1,2,3}和{7,9,18}是三角形顶点集合,{11,13,24,26}和{2,7,9,18}是平行四边形的顶点集合,{4,5,9,13,12,7}和{8,10,17,21,32,34}是六边形的顶点集合。
写一个程序,不断读入这个三角形网格的一个点集合,判断这些点是否是以下这些“可接受的”图形之一的顶点;三角形、平形四边形、六边形。
一个图形要成为可接受的,必须满足如下两个条件:(1)图形的每一条边必须和网格中的某条边重合(2)图形的所有的边必须长度相同输入规范输入将由总数未知的点集合组成。
每个点集将出现在文件的一个不同的行上。
一个集合中最多有6个点,每个点的范围被限制在1..32767。
输出规范对于输入文件中的每个点集,你的程序应当根据集合中的点的数目来判断这个集合代表了什么样的几何图形,例如6个点只能够代表一个六边形,等等。
输出必须是一系列的列出了每个点集及你的分析结果的行。
实例输入1 2 311 13 29 3126 11 13 244 5 9 13 12 71 2 3 4 54711 13 23 25实例输出1 2 3 are the vertices of a triangle.11 12 29 31 are not the vertices of an acceptable figure.26 11 13 24 are the vertices of a parallelogram.4 5 9 13 12 7 are the vertices of a hexagon.1 2 3 4 5 are not a vertices of an acceptable figure.47 are not the vertices of an acceptable figure.11 13 23 25 are not the vertices of an acceptable.6、旅行预算一个美国旅行代理商经常被要求去估计开车从一城市旅行至另一城市的最小费用。
他有一个在通常路线上的大多数加油站的列表。
列表包括了所有加油站的位置及当前每加仑汽油的价格。
为了简化估计费用的过程,代理商使用了以下的简化汽车驾驶员行为的规划:(1)除非汽车无法用油箱里的汽油达到下一个加油站(如果有的话)或目的地,在油箱里还有不少于最大容量一半的汽油时,驾驶员从不在加油站停下来。
(2)在每一个停下的加油站驾驶员总是将油箱加满。
(3)在一个加油站停下之后,驾驶员将为旅程在快餐和糖果上花去2.00元。
(4)在驶向加油站或目的地时,驾驶员不需要超过必需量的汽油,不需要“安全余量”。
(5)驾驶员开始旅行时油箱总是满的。
(6)在每个加油站付款时四舍五入到分(1元等于100分)。
你必须写一个程序以估计驾驶员在旅程上至少要为汽油和食品付多少钱。
输入规范程序的输入将由若干个对应不同的旅程的数据项组成。
每个数据项由若干信息行组成。
开始的2行给出了出发地和目的地的信息,数据项的后继行代表了路线上的加油站,每个加油站用一行表示。
下面是输入数据中数据项的精确格式及其含义。
第一行:一个实数---从出发地到目的地的距离(英里)。
第二行:三个实数及一个整数。
(1)第一个实数是汽车油箱的最大的容量(加仑)。
(2)第二个实数是汽车每加仑汽油可以行驶的英里数;(3)第三个实数是汽车在出发地城市加满油箱时的费用(单位:元);(4)整数(小于51)是路线上加油站的数目。
接下来的每一行:两个实数:(1)第一个实数是从出发地到加油站的距离(单位:英里);(2)第二个实数是该加油站出售的汽油每加仑的价格(单位:分)。
(3)数据项中的所有数据都是正的。
一条路线上的加油站根据其到出发地的距离递增排列。
路线上不存在这样的加油站,它到出发点的距离大于从出发点到目的地的距离。
每条路线上的加油站都被适当地安排以使得任何汽车都能够从出发地开到目的地。
(4)输入数据中若某行为一个负数则表示输入数据结束。
输出规范对于输入中的每个数据项,你的程序必须打印数据项编号以及一个给出了精确到分的汽油和食品的最小总费用,总费用必须包括开始时在出发地加满油箱的费用。
下面是两个不同的数据项的样例输入以及相应的正确的输出。
实例输入475.611.9 27.4 14.99 6102.0 99.9220.0 122.9255.3 147.9275.0 102.9277.6 112.9381.8 100.9516.315.7 22.1 20.87 3125.4 125.9297.9 112.9345.2 99.9-1实例输出Data Set #1minimum cost=$27.31Data Set #2minimum cost=$38.097、Code the treeA tree (i.e. a connected graph without cycles) with vertices numbered by the integers 1, 2, ..., n is given. The "Prufer" code of such a tree is built as follows: the leaf (a vertex that is incident to only one edge) with the minimal number is taken. This leaf, together with its incident edge is removed from the graph, while the number of the vertex that was adjacent to the leaf is written down. In the obtained graph, this procedure is repeated, until there is only one vertex left (which, by the way, always has number n). The written down sequence of n-1 numbers is called the Prufer code of the tree.Your task is, given a tree, to compute its Prufer code. The tree is denoted by a word of the language specified by the following grammar:T ::= "(" N S ")"S ::= " " T S| emptyN ::= numberThat is, trees have parentheses around them, and a number denoting the identifier of the root vertex, followed by arbitrarily many (maybe none) subtrees separated by a single space character. As an example, take a look at the tree in the figure below which is denoted in the first line of the sample input.Note that, according to the definition given above, the root of a tree may be a leaf as well. It is only for the ease of denotation that we designate some vertex to be the root. Usually, what we are dealing here with is called an "unrooted tree".Input SpecificationThe input contains several test cases. Each test case specifies a tree as described above on one line of the input file. Input is terminated by EOF. You may assume that 1<=n<=50.Output SpecificationFor each test case generate a single line containing the Prufer code of the specified tree. Separate numbers by a single space. Do not print any spaces at the end of the line.Sample Input Array (2 (6 (7)) (3) (5 (1) (4)) (8))(1 (2 (3)))(6 (1 (4)) (2 (3) (5)))Sample Output5 2 5 26 2 82 32 1 6 2 68、CPCI/MCAInput file: cpci.inCPCI/MCA is another type of team contest, different from ACM/ICPC that one team can only consist of three team members at maximum. In CPCI/MCA, there is no restriction for the number of team members. However, the more team members, the more effort on their communication in the teamwork.Now, you are asked to help the contest director to arrange the contest rooms. The host prepared several standard rooms on fixed capacity sized by number of people in. You should give a schedule to arrange all team members into contest rooms with the(1) All members from the same team should be arranged into the same room(2) The number of peoples arranged into the same room should not exceed the fixed capacity of the standard room.To save the budget, we must find the optimal solution with the minimum number of rooms to arrange all teams.For instance, suppose the capacity of the standard room is 10. Moreover, we have 5 teams totally. The numbers of team members of each team are 1, 4, 10, 5 and 2. So, one of the optimal solution is using 3 standard rooms that room 1 for team 3, room 2 for team 1 and team 2, and room 3 for team 4 and 5.Input (from cpci.in)The format of input file is as follows:The file line of the input file contains the number of test cases. For each test case, there have two parts:(1) one line with two items: room capacity C and the number of teams T;(2) T lines for the number of members of each team M i (1≤i≤T), one team per line. Note: 1≤C≤1000, 1≤T≤250, 1≤M i ≤100.OutputFor each test case, just output the result of the optimal solution, e.g. the minimum number of standard rooms to be used for that case. We give one line for the output of one case.Sample Input110 51 4105 2Sample Output3。