1011. World Cup Betting (20)

题目链接:http://www.patest.cn/contests/pat-a-practise/1011

题目:

  
  
  
  
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

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

分析:

就是让你找到一个比赛列表中胜算(odds)最大的进行投注,进行收益。计算方法是:在每场比赛的三个候选项中选取一个胜算最大的,进行投注,最后胜算累成再乘以65%,减去成本(即投注的钱),乘以2。相当于一注2元的意思吧。

案例分析:

可以看到题目中的一个案例,记住是按行选择胜率最大的,而不是按列来。

第一行选择2.5,并记录其对应的T,第二行选择3.0,并记录其对应的T,第三行记录其4.1,并记录其W,然后把三个数相乘,再乘以65%,再减去1,结果再乘以2。

AC代码:

#include<iostream>
using namespace std;
double a[3][3];//记录原始数据
double max[3];//记录每行的最大值
int ans[3];
char s[3] = {
 'W','T','L'
};
int main(void){
 int i,j;
 for(i = 0; i < 3; i ++){
  for(j = 0; j < 3; j ++){
   scanf("%lf",&a[i][j]);
  }
 }
 for(i = 0; i < 3; i ++){
  max[i] = -1;
  ans[i] = -1;
 }//init()初始化
 for(i = 0; i < 3; i ++){
  for(j = 0; j < 3; j ++){
   if(a[i][j] > max[i]){
    max[i] = a[i][j];
    ans[i] = j;
   }
  }
 }
 double sum = 1.0;
 for(i = 0; i < 3; i ++){
  printf("%c ", s[ans[i]]);
  sum *= max[i];
 }
 printf("%.2lf",sum * 0.65 * 2 - 2);
 
 return 0;
}


 

1011. World Cup Betting (20)_第1张图片

——Apie陈小旭



你可能感兴趣的:(pat)