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

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

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

Inputcode

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

Outputblog

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

Sample Inputip

1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1

Sample Outputci




輸入3行3列 9個數字
每行的3個數字表示一場比賽的三種可能性
要想得到最大利潤, 則取每場比賽的三個可能中獲利最大的那個
再帶入公式計算最大總利潤

T T W 37.98
#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\n" , result) ; 

    return 0 ; 
}
相關文章
相關標籤/搜索