b_lc_移除石子的最大得分(贪心+堆)

大小为 a​​​​​​、b 和 c​​​​​​ 的三堆石子。每回合要从两个不同的非空堆中取出一颗石子,并在得分上加 1 分。当存在两个或更多的空堆时,游戏停止。求可以得到的 最大分数。(1 <= a, b, c <= 10)

思路:要求最大得分,自然是每次从最大、次大这两堆中各取1颗,但是不必每次取一颗,可以取small-medium颗

class Solution {
public:
    int maximumScore(int a, int b, int c) {
        int ans = 0 ;
        priority_queue<int> q;
        q.push(a), q.push(b), q.push(c);
        while (true) {
            int big = q.top(); q.pop();
            int med = q.top(); q.pop();
            int sma = q.top();
            if (med == 0) break;
            int take = max(1, med - sma);
            ans += take, big -= take, med -= take;
            q.push(big), q.push(med);
        }
        return ans;
    }
};
原文地址:https://www.cnblogs.com/wdt1/p/14404309.html