湖南省第六届大学生计算机程序设计竞赛 The Sixth Hunan Collegiate Programming Contest 主办:湖南省教育厅 协办:湖南省高

 

 

湖南省第六届大学生计算机程序设计竞赛

The Sixth HunanCollegiate Programming Contest

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

主办:湖南省教育厅

协办:湖南省高等教育学会计算机教育专业委员会

承办:长沙理工大学

 

 

 

2010年10月31日

 

本次比赛11道题目,共13页。如有缺页,请立即通知赛场工作人员。

所有题目均采用标准输入输出,请不要读写任何文件。

所有题目的正确输出均是惟一的。你的输出只有和正确输出完全一致时才能通过。


题目A

汽水瓶

 

有这样一道智力题:“某商店规定:三个空汽水瓶可以换一瓶汽水。小张手上有十个空汽水瓶,她最多可以换多少瓶汽水喝?”答案是5瓶,方法如下:先用9个空瓶子换3瓶汽水,喝掉3瓶满的,喝完以后4个空瓶子,用3个再换一瓶,喝掉这瓶满的,这时候剩2个空瓶子。然后你让老板先借给你一瓶汽水,喝掉这瓶满的,喝完以后用3个空瓶子换一瓶满的还给老板。如果小张手上有n个空汽水瓶,最多可以换多少瓶汽水喝?

 

输入

输入文件最多包含10组测试数据,每个数据占一行,仅包含一个正整数n(1<=n<=100),表示小张手上的空汽水瓶数。n=0表示输入结束,你的程序不应当处理这一行。

 

输出

对于每组测试数据,输出一行,表示最多可以喝的汽水瓶数。如果一瓶也喝不到,输出0。

 

样例输入

样例输出

3

10

81

0

1

5

40

 


题目B

弟弟的作业

 

你的弟弟刚做完了“100以内数的加减法”这部分的作业,请你帮他检查一下。每道题目(包括弟弟的答案)的格式为a+b=c或者a-b=c,其中ab是作业中给出的,均为不超过100的非负整数;c是弟弟算出的答案,可能是不超过200的非负整数,也可能是单个字符"?",表示他不会算。

 

输入

输入文件包含不超过100行,以文件结束符结尾。每行包含一道题目,格式保证符合上述规定,且不包含任何空白字符。输入的所有整数均不含前导0。

 

输出

输出仅一行,包含一个非负整数,即弟弟答对的题目数量。

 

样例输入

样例输出

1+2=3

3-1=5

6+7=?

99-0=99

2

 


题目C

数字整除

 

定理:把一个至少两位的正整数的个位数字去掉,再从余下的数中减去个位数的5倍。当且仅当差是17的倍数时,原数也是17的倍数 。

例如,34是17的倍数,因为3-20=-17是17的倍数;201不是17的倍数,因为20-5=15不是17的倍数。输入一个正整数n,你的任务是判断它是否是17的倍数。

 

输入

输入文件最多包含10组测试数据,每个数据占一行,仅包含一个正整数n(1<=n<=10100),表示待判断的正整数。n=0表示输入结束,你的程序不应当处理这一行。

 

输出

对于每组测试数据,输出一行,表示相应的n是否是17的倍数。1表示是,0表示否。

 

样例输入

样例输出

34

201

2098765413

1717171717171717171717171717171717171717171717171718

0

1

0

1

0

 


题目D

 

台球碰撞

 

在平面直角坐标系下,台球桌是一个左下角在(0,0),右上角在(L,W)的矩形。有一个球心在(x,y),半径为R的圆形母球放在台球桌上(整个球都在台球桌内)。受撞击后,球沿极角为a的射线(即:x正半轴逆时针旋转到此射线的角度为a)飞出,每次碰到球桌时均发生完全弹性碰撞(球的速率不变,反射角等于入射角)。

 

 

如果球的速率为vs个时间单位之后球心在什么地方?

 

输入

输入文件最多包含25组测试数据,每个数据仅一行,包含8个正整数L,W,x,y,R,a,v,s(100<=L,W<=105,1<=R<=5, R<=x<=L-R, R<=y<=W-R,0<=a<360, 1<=v,s<=105),含义见题目描述。L=W=x=y=R=a=v=s=0表示输入结束,你的程序不应当处理这一行。

 

输出

对于每组数据,输出仅一行,包含两个实数x, y,表明球心坐标为(x,y)。xy应四舍五入保留两位小数。

 

样例输入

样例输出

100 100 80 10 5 90 2 23

110 100 70 10 5 180 1 9999

0 0 0 0 0 0 0 0

80.00 56.00

71.00 10.00

 


题目E

内部收益率

 

在金融中,我们有时会用内部收益率IRR来评价项目的投资财务效益,它等于使得投资净现值NPV等于0的贴现率。换句话说,给定项目的期数T、初始现金流CF0和项目各期的现金流CF1, CF2, ...,CFTIRR是下面方程的解:

 

 

为了简单起见,本题假定:除了项目启动时有一笔投入(即初始现金流CF0 < 0)之外,其余各期均能赚钱(即对于所有i=1,2,...,TCFi> 0)。根据定义,IRR可以是负数,但不能大于-1。

 

 

输入

输入文件最多包含25组测试数据,每个数据占两行,第一行包含一个正整数T(1<=T<=10),表示项目的期数。第二行包含T+1个整数:CF0, CF1, CF2,..., CFT,其中CF0< 0, 0 < CFi< 10000 (i=1,2,...,T)。T=0表示输入结束,你的程序不应当处理这一行。

 

输出

对于每组数据,输出仅一行,即项目的IRR,四舍五入保留小数点后两位。如果IRR不存在,输出"No",如果有多个不同IRR满足条件,输出"Too many"(均不含引号)

 

样例输入

样例输出

1

-1 2

2

-8 6 9

0

1.00

0.50

 

 


Problem F

Biggest Number

 

You have a maze with obstacles and non-zero digits in it:

 

 

You can start from any square, walk in themaze, and finally stop at some square. Each step, youmay only walk into one of the fourneighbouring squares (up, down, left, right) and you cannot walk into obstacles or walk into a square morethan once. When you finish, you can get a number by writing down the digits youencounter in the same order as you meet them. For example, you can get numbers 9784, 4832145 etc. The biggestnumber you can get is 791452384, shown in the picture above.

 

Your task is to find the biggest number you canget.

 

Input

There will be at most 25 test cases. Eachtest begins with two integers R and C (2<=R,C<=15,R*C<=30), the number of rows and columns of the maze. The next Rrows represent the maze. Each line contains exactly C characters(without leading or trailing spaces), each of them will be either '#' or oneof the nine non-zero digits. There will be at least one non-obstacle squares(i.e. squares with a non-zero digit in it) in the maze. The input is terminated by a test case with R=C=0, youshould not process it.

 

Output

For each test case, print the biggest number you can find, on a single line.

 

Sample Input

Output for the Sample Input

3 7

##9784#

##123##

##45###

0 0

791452384

 


Problem G

Repairing a Road

 

You live in a small town with Rbidirectional roads connecting C crossings and you want to go from crossing 1 to crossing C as soon as possible. Youcan visit other crossings before arriving at crossing C, but it’s notmandatory.

 

You have exactly one chance to ask your friend to repair exactly one existing road, fromthe time you leave crossing 1. If he repairs the i-th road for t units of time, thecrossing time after that would be viai-t.It's not difficult to see that it takes vi units of time tocross that road if your friend doesn’t repair it.

 

You cannot start to cross the road whenyour friend is repairing it.

 

Input

There will be at most 25 test cases. Eachtest case begins with two integers C and R (2<=C<=100,1<=R<=500). Each of the next R lines contains two integers xi, yi (1<=xi,yi<=C) and two positivefloating-point numbers vi and ai (1<=vi<=20,1<=ai<=5),indicating that there is a bidirectional road connecting crossing xiand yi, with parameters vi and ai(see above). Each pair of crossings can be connected byat most one road. The input is terminated by a test case with C=R=0,you should not process it.

 

Output

For each test case, print the smallest timeit takes to reach crossing C from crossing 1, rounded to 3 digits after decimal point. It’s always possible to reach crossing Cfrom crossing 1.

 

Sample Input

Output for the Sample Input

3 2

1 2 1.5 1.8

2 3 2.0 1.5

2 1

1 2 2.0 1.8

0 0

2.589

1.976


题目H

射击游戏

 

A和B在玩一个射击游戏,战场由若干单位正方形积木组成。积木占据了连续的若干列,且图形周长等于它最小包围矩形的周长。下图(a)是一个合法的战场,但(b)和(c)都不是:(b)中有空列;(c)的图形周长为14,而最小包围矩形(用虚线画出)的周长为12。受重力影响,每个积木的正下方要么是地面,要么是另一个积木。为了让战场看上去错落有致、玩着更刺激,它不能恰好是一个矩形(即:不能每列积木都一样高)。

 

游戏规则如下:

1、 A和B轮流射击,A先射击。

2、  每次射击时,首先选择一行(该行必须至少有一个积木),以及“左”和“右”中的一个方向,然后往这个方向开火。子弹的威力为1~3的均匀随机整数(即:威力为1、2、3的概率各为1/3),表示子弹能打掉的积木个数,被打掉的积木将直接从战场中消失。如果该行的积木个数小于威力值,则子弹将在打掉该行所有积木后消失。例如,若选择往右射击从下往上数第3行,且威力为2,且这一行一共有4个积木,则最左边的两个积木将被打掉。注意:这两个积木可以不连续。

3、 每次射击完成后,悬空的积木垂直往下落。所有积木不再下落后,下一位选手才能开始射击。

4、 谁打掉了最后一个积木,谁就获胜。

 

假定开局是,根据规则1,A先开火。射击后,B可能面临的后续局面中的其中三个如下表:

 

行编号(从下往上数)

子弹前进方向

威力(随机值)

刚射击后

积木稳定后

2

从右往左

1

(同左图)

1

从右往左

2

1

从左往右

3

 

假定A和B都足够聪明,采取让自己获胜概率尽量高的策略,你的任务是计算出A获胜的概率。

 

输入

输入文件最多包含25组测试数据,每个数据仅包含两行,第一行是整数n(1<=n<=6),即积木的列数。第二行包含n个正整数h1, h2,..., hn(1<=hi<=6),表示从左往右数第i列的高度。积木的排列方式保证符合题目描述(即:图形周长等于它最小包围矩形的周长,且各列的高度不全相同)。n=0表示输入结束,你的程序不应当处理这一行。

 

输出

对于每组数据,输出仅一行,即A获胜的概率,四舍五入保留六位小数。

 

样例输入

样例输出

3

2 1 1

0

0.555556

 


题目I

战场的数目

 

在上题中,假设战场的图形周长为p,一共有多少种可能的战场?

 

例如,p<8时没有符合要求的战场,p=8时有2种战场:

p=10有9种战场:

 

要求输出方案总数模987654321的值。

 

输入

输入文件最多包含25组测试数据,每个数据仅包含一行,有一个整数p(1<=p<=109),表示战场的图形周长。p=0表示输入结束,你的程序不应当处理这一行。

 

输出

对于每组数据,输出仅一行,即满足条件的战场总数除以987654321的余数。

 

样例输入

样例输出

7

8

9

10

0

0

2

0

9

 

 


Problem J

Infinite Dictionaries

 

A dictionary is a set of key-value pairs,for example:

 

{'color':'red', 'price':2, 7:'test',100:-100}

 

As you can see, keys and values can be stringsor integers. What’s more, values can also be dictionaries orvariable references. Here is the formaldefinition of terms that will be used soon:

 

key  ::=      INTEGER | STRING

value ::=      INTEGER | STRING | dict

pair  ::=      key ':' value

dict  ::=      '{' [pair (',' pair)*] '}'

var   ::=      'a'|'b'|'c'|...|'z'

slot  ::=      var('[' key ']')*

lvar  ::=      slot

rvar  ::=      slot | value

 

Here ('[' key ']')* meanszero or more subscripts, [pair(',' pair)*] means zero or more key-value pairs.

 

Strings are always enclosed by singlequotes ('') and consists of up to 10 lower-case letters. Integers always haveabsolute values of no more than 1000. You can insert spaces anywhere, exceptinside strings or integers. For example, { 'a':-1} and {'a' : -1   } are the same, but {'a b':1}and {'a':- 1} are both illegal.

 

Your task is to execute a series ofcommands and print the results. There are 3 kinds of commands:

 

1. Assignment: <lvar> = <rval>

 

After assigning a slot to aslot (rather than a value), the left-hand slot willbe holding a reference to the right-hand. For example, Afterexecuting the following commands, b[1][0] is 1, rather than 0:

 

a = {0:0}

b = {}

b[1] = a

a[0] = 1

 

Slots must be assigned before it is read or subscripted, and integers and strings cannot besubscripted. Consider the following comammd list:

 

c = {}

c[0] = 3

c[1] =c[0]

d[0] ='i'

c = d

d =c[1]['a']

c[2][2] =2

 

The first three commands are legal, but thenext two are both illegal because slot d must be assigned before it is read orsubscripted. The last three are also illegal.

 

2. Length: length(<slot>)

 

Output the number of key-value pairs in theslot. Note that nested pairs are not counted. For example:

 

a = {0:{0:0, 1:1}}

length(a)

 

will output 1, not 3. Inthis command, it is guaranteed that <slot> is storing a dictionary, not a string or an integer.

 

3. Infinity test: test(<slot>)

 

If the slot can be subscripted indefinitely,output 1. Otherwise, output 0. For example, after executing the followingcommand list:

 

d = {}

d[0] = d

 

Then d is infinite, since d[0][0][0][0][0][0]... is always d. In this command, it is guaranteed that <slot> is storing a dictionary, not a string or an integer.

 

Input

The input contains at most 10000 lines ofcommands, each line will be non-empty and will contain no more than 300characters. All the commands are legal.

 

Output

Print the output (one line for eachlength/test command).

 

Sample Input

Output for the Sample Input

c = {}

d = {'color': 'red', 'price': 2, 7: 'test', 100: -100}

length(d)

d[7] = {'this': 'is', 'a': 'book'}

length(d)

d[8] = {'this' : 'is', 'another' : {'a' : 'book', 'b': 'book2'} }

length(d)

c[7] = c

test(c)

test(d)

length(c)

d[0] = c

length(d)

test(d[0])

4

4

5

1

0

1

6

1

 

Notes

The term definitions in this problem use a modifiedBNF grammar notation that is described in the official documentation of the Pythonprogramming language. Here is the explanation of the notation, extracted fromthe documentation:

 

Each rule beginswith a name (which is the name defined by the rule) and ::=. A vertical bar (|)is used to separate alternatives; it is the least binding operator in thisnotation. A star (*) means zero or more repetitions of the preceding item;likewise, a plus (+) means one or more repetitions, and a phrase enclosed insquare brackets ([ ]) means zero or one occurrences (in other words, theenclosed phrase is optional). The * and + operators bind as tightly aspossible; parentheses are used for grouping. Literal strings are enclosed inquotes. White space is only meaningful to separate tokens. Rules are normallycontained on a single line; rules with many alternatives may be formattedalternatively with each line after the first beginning with a vertical bar.

 


Problem K

Tetrahedrons and Spheres

 

There are a tetrahedrons and bspheres in the 3D-splace, you’re asked to calculate the volume occupied by atleast one of them (i.e. volume of the union of the objects).

 

Input

There will be at most 20 testcases. Each case begins with two integers a, b, the number oftetrahedrons and the number of spheres (1<=a,b<=5). Thenext a lines each contains 12 integers: x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4,the coordinates (xi, yi, zi)(1<=i<=4) of the four vertices  of a tetrahedron. The next b lines each contains 4 integers x, y, z, r, the coordinates of the center (x, y, z) and the radius r(r<=3).All the coordinate values are integers with absolute values no more than 5. Theinput is terminated by a=b=0.

 

Output

For each test case, print a single line,the volume occupied by at least one of them, rounded to threedecimal points.

 

Sample Input

Output for the Sample Input

1 1

0 0 4 1 0 4 0 1 4 0 0 5

0 0 0 1

0 0

4.356

 解题报告:在我上传的资源里面有

你可能感兴趣的:(教育,input,each,documentation,Dictionary,output)