zoukankan      html  css  js  c++  java
  • 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;
        }
    };
    
  • 相关阅读:
    整型数字转utf8
    cmake构建时指定编译器架构(x86 or x64)
    tcp echo server libuv
    VS2015编译boost1.62
    android rom开发
    游戏昵称
    乐观锁和悲观锁
    数据库锁机制
    MySQL事务实现原理
    MySQL事务
  • 原文地址:https://www.cnblogs.com/wdt1/p/14404309.html
Copyright © 2011-2022 走看看