1011 World Cup Betting (20)(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.
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
题目要求:
足球赛下赌注,概率高的说明压的人少,一旦赢了赚的钱最多,这里就是求三场比赛每场比赛能赢最多钱的押注以及最后所能获得的最多的钱,按公式(4.1*3.0*2.5*65%-1)*2 = 37.98,最后保留两位小数
解题思路:
这题非常简单,固定好的三场比赛,三种押注方式,用float二维数组a存储,a[i][j]代表第i场比赛第j种押注方式。然后找出每场中最大的数,输出时哪个押注方式,最后计算最大利润输出
注意:
存储利润以及输入数据均要用float,别用Int
完整代码:
#include<iostream>
#include<iomanip>
using namespace std;
float a[3][3];
int findmax(int i){
float max = a[i][0];
int j,index = 0;
for(j=1;j<3;j++){
if(a[i][j]>max){
max = a[i][j];
index = j;
}
}
return index;
}
int main(){
int i,j,index;
float pro=1;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cin >> a[i][j];
}
}
for(i=0;i<3;i++){
index = findmax(i);
pro *= a[i][index];
if(index == 0){
cout<<"W"<<" ";
}else if(index == 1){
cout<<"T"<<" ";
}else{
cout<<"L"<<" ";
}
}
pro = pro*0.65*2 - 2;
cout<<fixed<<setprecision(2)<<pro;
return 0;
}