PAT Advanced 1011. World Cup Betting

发布时间 2023-05-23 15:28:36作者: 十豆加日月

PAT Advanced 1011. World Cup Betting

1. Problem Description:

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

2. 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 WT and L.

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

4. Sample Input:

1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1

5. Sample Output:

T T W 39.31

6. Performance Limit:

Code Size Limit
16 KB
Time Limit
400 ms
Memory Limit
64 MB

思路:

按照题意编写即可,找出每局游戏中odd最大的选项,这里我使用map<double, char>类型存储每局游戏的信息,其中key对应每个选项的odd值,value对应三种选项,利用map类型默认按照key升序排列的特性找出odd最大的选项并进行输出。

这里一开始没看懂题意,以为odd是概率的意思,还在奇怪为什么三个选项的概率之和不为1。。。问了chatGPT之后才知道这里odd代表赔率,所以实际上在选择赔率最大的选项,可是一般赔率越大的事件不是发生的概率越小吗?对于这种选择只能用两个字形容,“土块”。

可以参考大佬的题解:1011. World Cup Betting (20)-PAT甲级真题_柳婼 1011_柳婼的博客-CSDN博客 ,比较简洁。

My Code & Result:

#include <iostream>
#include <map>
using namespace std;

int main(void)
{
    map<double, char> game;
    double temp = 0.0;
    int i=0; // iterator
    double profit = 1.0;

    for(i=0; i<3; ++i)
    {
        cin >> temp;
        game[temp] = 'W';
        cin >> temp;
        game[temp] = 'T';
        cin >> temp;
        game[temp] = 'L';

        if(i==0) cout << (--game.end())->second;
        else cout << " " << (--game.end())->second;
        profit *= (--game.end())->first;

        game.clear();
    }

    printf(" %.2f\n", (profit*0.65-1)*2);
    
    return 0;
}
Compiler
C++ (g++)
Memory
496 / 65536 KB
Time
5 / 400 ms