PAT A1011 World Cup Betting (20)

来源:互联网 发布:java用户密码加密算法 编辑:程序博客网 时间:2024/06/05 08:51

题目地址:https://www.patest.cn/contests/pat-a-practise/1011

题目描述:

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.

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%.

For example, 3 games’ odds are given as the following:

W T L
1.1 2.5 1.7
1.2 3.0 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.0*2.5*65%-1)*2 = 37.98 yuans (accurate up to 2 decimal places).

输入格式:

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.

输出格式:

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.

输入样例:

1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1

输出样例:

T T W 37.98


题意:

给出三场比赛的赔率,正确率为%65,每次投注为 2 元,问最大期望收入,并输出最大收入时的比赛结果。
更通俗的题意如下:
给出三行数据,代表三场比赛。每行有三个浮点整数,从左至右分别代表W(Win)、T(Tie)、L(Lost)。现在需要从每行的 W、T、L 中选择最大的数,并输出三行各自选择的是哪一个。之后,不妨设三行各自的最大数据为 a、b、c,并计算最大收益(a * b * c * 0.65 - 1)* 2 并输出。

样例解释:

1.1 2.5(T最大) 1.7
1.2 3.0(T最大) 1.6
4.1(W最大) 1.2 1.1

这里可以看出比赛结果分别为 T T W,最大收益为(2.5 * 3 * 4.1 * 0.65 - 1)* 2


解题思路:

令 ans 记录最大收益,初值为 1.0
每读入一行,就找到该行最大的数字,并输出其下标对应的输赢情况(W/T/L),同时令 ans 累乘该最大值。最后输出(ans * 0.65 - 1) * 2 即可

这里有一个小技巧:

用一个 char S[ ] = { ‘W’ , ‘T’ , ‘L’}数组来表示比赛结果,即 s[0] = ‘w’、s[1] = ‘T’、S[2] = ‘L’,这要比用 if else 来输出 W/T/L 的方法更简便。

注意:该收益公式为(max_1 * max_2 * max_3 * 0.65 - 1)* 2,其中 max_i 为第 i 行三个数字中的最大值。


C++完整代码如下:

#include<cstdio>char S[3] = {'W','T','L'}; int main(){    double ans = 1.0, tmp, a;    int idx;                        //记录每行最大数字的下标    for(int i = 0; i < 3; i++){        tmp = 0.0;        for(int j = 0; j < 3; j++){ //寻找该行最大的数字存于 tmp            scanf("%lf", &a);            if(a > tmp){                tmp = a;                idx = j;            }         }        ans *= tmp;                 //按公式累乘        printf("%c ",S[idx]);       //输出对应的比赛结果     }     printf("%.2f", (ans * 0.65 - 1) * 2);   //输出最大收益    return 0;  }
0 0
原创粉丝点击