1011 World Cup Betting (20)(20 分)

ball 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).

Input

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.

Output

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.

Sample Input

1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1

Sample Output

T T W 37.98


输入3行3列 9个数字
每行的3个数字表示一场比赛的三种可能性
要想获得最大利润, 则取每场比赛的三个可能中获利最大的那个
再带入公式计算最大总利润

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std ; 

#define maxn 10

char flag[maxn] = {'W','T','L'} ; // 每场比赛三种比赛结果的标志
double num[maxn][maxn] ; 
int maxipos[maxn] ; 

// 返回第 i 场比赛中获得利润最大的的那一场的下标
int check(int i){
    int maxinum = num[i][0] ; 
    int pos = 0 ; 
    for(int j=0 ; j<3 ; j++){
        if(maxinum < num[i][j]){
            maxinum = num[i][j] ; 
            pos = j ; 
        }
    }
    return pos ; 
}

int main(){

    int n = 3 ; 

    for(int i=0 ; i<n ; i++){
        for(int j=0 ; j<n ; j++){
            cin >> num[i][j] ; 
        }
    }

    double result = 1.0 ; 
    for(int i=0 ; i<n ; i++){
        int pos = check(i) ; 
        result *= num[i][pos] ; // 累乘三场比赛的最大获利

        maxipos[i] = pos ; 

    }

    result = (result * 0.65 -1) * 2 ; // 带入公式,题目说了下注 2 元
    
    for(int i=0 ; i<n ; i++){
        cout << flag[maxipos[i]] << " " ; 
    }
    printf("%.2f
" , result) ; 

    return 0 ; 
}
原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9515374.html