(Python实现)PAT 1011 World Cup Betting (20 分)

1011 World Cup Betting (20 分)
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.
随着2010年世界杯的继续,世界各地的球迷们变得越来越兴奋,因为来自最好球队的最好的球员正在为南非的世界杯奖杯而战斗。同样,足球迷们也在用各种方式赌世界杯,把钱花在他们说到做到的事情上。

Chinese Football Lottery provided a “Triple Winning” game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results – namely W for win, T for tie, and L for lose. There was an odd assigned to each result. The winner’s odd would be the product of the three odds times 65%.
中国足球彩票提供了一种“三赢”的游戏。获胜的规则很简单:首先选择任意三个游戏。然后,对每一场选定的比赛,对三种可能的结果中的一种下注——即“W”表示赢,“T”表示平,“L”表示输。每个结果都有一个奇数。获胜者的奇数是3个奇数乘以65%的结果。

For example, 3 games’ odds are given as the following:
例如,3个游戏的赔率如下所示:

 W    T    L
1.1  2.5  1.7
1.2  3.1  1.6
4.1  1.2  1.1

To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. If each bet takes 2 yuans, then the maximum profit would be (4.1×3.1×2.5×65%−1)×2=39.31 yuans (accurate up to 2 decimal places).
为了获得最大利润,在第三场博弈中必须购买W,在第二场博弈中必须购买T,在第一场博弈中必须购买T。如果每次下注2元,则最大收益为(4.1×3.1×2.5×65%−1)×2=39.31元(精确到小数点后2位)。

Input Specification:
Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to W, T and L.
每个输入文件包含一个测试用例。每个案例包含3场比赛的投注信息。每个游戏占据一行,有三个不同的赔率,分别对应“W”、“T”和“L”。

Output Specification:
For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.
对于每个测试用例,在一行中打印每个游戏的最佳赌注,最大利润精确到小数点后2位。字符和数字之间必须有一个空格。

Sample Input:

1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1

Sample Output:

T T W 39.31

作者:CHEN, Yue
单位:浙江大学
代码长度限制:16 KB
时间限制:400 ms
内存限制:64 MB

解题思路:
定义一个函数,判断输出的字母以及输出的最大值,然后计算得到相应结果输出即可。

代码:

def max_num(x):
    g1 = eval(x[0])
    g2 = eval(x[1])
    g3 = eval(x[2])
    if g1 >= g2 and g1 >= g3:
        return "W", g1
    if g2 >= g1 and g2 >= g3:
        return "T", g2
    if g3 >= g1 and g3 >= g2:
        return "L", g3

if __name__ == "__main__":
    game1 = input().split()
    game2 = input().split()
    game3 = input().split()

    a, num1 = max_num(game1)
    b, num2 = max_num(game2)
    c, num3 = max_num(game3)
    num = (num1 * num2 * num3 * 0.65 - 1) * 2
    print(a + ' ' + b + ' ' + c + ' ', end="")
    print("%.2f" %num)

提交记录:
(Python实现)PAT 1011 World Cup Betting (20 分)_第1张图片

你可能感兴趣的:(每日一题,python)