![]() |
#2
freedomz2008-04-10 05:04
翻译
doc版本的例题可以从附件里下载
############################################ # 例题开始 ############################################ 今天,法国世界足球杯已经结束,而优胜者将是从剩下16个国家选出(图) 在这16个国家之中,每一个 A对B的比赛,A胜出的几率将会被告知。 这将会给予你足够的信息来推算任何一个国家得到最后胜利的几率。 比如说,德国(Germany)赢墨西哥(Mexico)的几率是80% 罗马尼亚(Romania)赢Croatia(希腊旁边的国家,不知中文名)的几率是60% 德国(Germany)赢罗马尼亚(Romania)的几率是70% 德国(Germany)赢Croatia的几率是90% 那么德国达到把半赛的几率是80% * (70% * 60% + 90% * 40%) = 62.4%. 你的任务是写一个推算所有国家胜出98世界杯的的几率 输入: 前16行是国家名称,顺序如图,接下来是一个16x16 的数组 例: i= A j=B i1j2 = A战胜B的几率,以此类推。 由此可见,如果 i1j2(A胜B)=65, 自然而然, i2j1(B胜A)=35 i甲j乙 + i乙j甲 = 100 i1j1 i1j2 i1j3 … … i1j16 i2j1 … … i3j1 … … … … … … … … i16j1 … … … … i16j16 输出: 16行 “xxxxxxxxxx p=y.yy%” xxxxxxxxxx = 国家名称 (无论长度,必须占10格) p指的是probability=概率 -->回忆上诉 p(ij)+p(ji) = 100 y.yy = 求得的概率,必须是 2位小数点 读入以下文件,并对其进行计算 文件开始 ------------------------------------ Brazil Chile Nigeria Denmark Holland Yugoslavia Argentina England Italy Norway France Paraguay Germany Mexico Romania Croatia 50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50 35 50 35 45 40 35 35 50 30 40 25 40 25 40 35 35 50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50 40 55 40 50 45 40 40 55 35 45 30 45 30 45 40 40 45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45 50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50 50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50 35 50 35 45 40 35 35 50 30 40 25 40 25 40 35 35 55 70 55 65 60 55 55 70 50 60 45 60 45 60 55 55 45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45 60 75 60 70 65 60 60 75 55 65 50 65 50 65 60 60 45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45 60 75 60 70 65 60 60 75 55 65 50 65 50 65 60 60 45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45 50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50 50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50 -------------------------------------------------- 文件结束 应得答案: -------------------------------------------- Brazil p=8.54% Chile p=1.60% Nigeria p=8.06% Denmark p=2.79% Holland p=4.51% Yugoslavia p=7.50% Argentina p=8.38% England p=1.56% Italy p=9.05% Norway p=3.23% France p=13.72% Paraguay p=3.09% Germany p=13.79% Mexico p=3.11% Romania p=5.53% Croatia p=5.53% [[it] 本帖最后由 freedomz 于 2008-4-10 05:09 编辑 [/it]] |
For each possible match A vs. B between these 16 nations, you are given the probability that team A wins against B. This (together with the tournament mode displayed above) is sufficient to compute the probability that a given nation wins the World Cup. For example, if Germany wins against Mexico with 80%, Romania against Croatia with 60%, Germany against Romania with 70% and Germany against Croatia with 90%, then the probability that Germany reaches the semi-finals is 80% * (70% * 60% + 90% * 40%) = 62.4%.
Your task is to write a program that computes the chances of the 16 nations to become the World Champion '98.
Input
The input will contain just one test case.
The first 16 lines of the input file give the names of the 16 countries, from top to bottom according to the picture given above.
Next, there will follow a 16 x 16 integer matrix P where element pijgives the probability in percent that country #i defeats country #j in a direct match. Country #i means the i-th country from top to bottom given in the list of countries. In the picture above Brazil is #1 and Germany is #13, so p1,13=55 would mean that in a match between Brazil and Germany, Brazil wins with a probability of 55%.
Note that matches may not end with a draw, i.e. pij + pji = 100 for all i,j.
Output
Output 16 lines of the form "XXXXXXXXXX p=Y.YY%", where XXXXXXXXXX is the country's name, left-justified in a field of 10 characters, and Y.YY is their chance in percent to win the cup, written to two decimal places. Use the same order of countries like in the input file.
Sample Input
Brazil
Chile
Nigeria
Denmark
Holland
Yugoslavia
Argentina
England
Italy
Norway
France
Paraguay
Germany
Mexico
Romania
Croatia
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
35 50 35 45 40 35 35 50 30 40 25 40 25 40 35 35
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
40 55 40 50 45 40 40 55 35 45 30 45 30 45 40 40
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
35 50 35 45 40 35 35 50 30 40 25 40 25 40 35 35
55 70 55 65 60 55 55 70 50 60 45 60 45 60 55 55
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
60 75 60 70 65 60 60 75 55 65 50 65 50 65 60 60
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
60 75 60 70 65 60 60 75 55 65 50 65 50 65 60 60
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
Sample Output
Brazil p=8.54%
Chile p=1.60%
Nigeria p=8.06%
Denmark p=2.79%
Holland p=4.51%
Yugoslavia p=7.50%
Argentina p=8.38%
England p=1.56%
Italy p=9.05%
Norway p=3.23%
France p=13.72%
Paraguay p=3.09%
Germany p=13.79%
Mexico p=3.11%
Romania p=5.53%
Croatia p=5.53%