題目
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.1 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.1×2.5×65%−1)×2=39.31 yuans (accurate up to 2 decimal places).
Input Specification:
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 Specification:
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.1 1.6
4.1 1.2 1.1
Sample Output:
T T W 39.31
題目解讀
人們為了慶祝“世界盃”,開辦了一個叫“三連勝”遊戲,規則如下:首先從所有比賽中隨機選擇三
個,然後對於每一個
遊戲做一個下注(W
代表贏,T
代表平,L
代表輸),每種結果都有對應的賠率;玩家最終能獲得利潤的所下注的三個結果的賠率的乘積x65%。
要求,輸出能獲得最大賠率的結果下,每一場比賽應該押 W
還是 T
還是 L
,並輸出所獲得的最大利潤。
看起來很牛逼,“世界盃”都出來了,好像還要會買股票,但其實,呵呵。。我這麼給你說吧:
三行輸入,每一行有三個數字,選擇其中最大的那個,如果它是第一個 輸出 W
,如果它是第二個,輸出 T
, 如果他是第三個,輸出 L
,並儲存這個最大的數。
三行輸入結束後,把儲存的三個最大的數做乘積
,再乘以 65%
,再減去1
,然後給這個結果 x 2
,輸出。
你可能從題目中沒太看出來這個利潤是咋算的,但是你看它最後給你的那個例子就明白了。
the maximum profit would be
(4.1×3.1×2.5×65%−1)×2=39.31
yuans (accurate up to 2 decimal places).
程式碼
就似乎比較大小,很容易理解,可以看一下這個char[]陣列的巧妙使用。
#include <iostream>
using namespace std;
int main() {
// 注意字串結束符包含了 \0,寫成c[3]會直接報錯
// W 贏 T 平 L 輸
char c[4] = {"WTL"};
double profit = 1.0;
// 每一行,是一個比賽三種結果的賠率
for (int i = 0; i < 3; ++i) {
double maxOdds = 0.0;
int index = 0;
for (int j = 0; j < 3; ++j) {
double temp;
cin >> temp;
// 買最大的賠率
if (temp > maxOdds) {
maxOdds = temp;
index = j;
}
}
// 最大的賠率對應的是 W / T / L
printf("%c ", c[index]);
// 利潤計算公式題目給出
profit *= maxOdds;
}
// 最終利潤
profit = (profit * 0.65 - 1) * 2;
printf("%.2f", profit);
return 0;
}