【问题标题】:number of rounds passing choclate通过巧克力的回合数
【发布时间】:2013-03-30 18:35:19
【问题描述】:

我们正在玩一个游戏,其中有 n 个孩子围成一圈坐着。他们每个人都有一些巧克力。巧克力的总数使得它们可以平均分配给所有孩子。

在一轮中,任何一个孩子向左或向右传递一颗巧克力。我们需要回答,至少需要多少轮这样的轮次才能让所有人拥有相同数量的巧克力。

给出了孩子的数量 n 和每个孩子的巧克力数量。

我们应该应用什么算法??

【问题讨论】:

    标签: algorithm combinatorics


    【解决方案1】:

    我的启发是:

    while (not equally divided)
        find kid A with the most chocolates
        while (A has more that he should)
            find closest kid B with fewer than he should
                pass one from A to B and add to the number of moves (taking distance into account)
    

    【讨论】:

    • 我怀疑这是否是最佳选择。
    • 我也怀疑。你在寻找什么样的答案?算法最优的算法和数学证明?
    • 我正在寻找一种能够找到最佳答案的算法。我不太热衷于数学证明。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 2022-10-25
    • 2020-12-22
    • 2014-11-08
    相关资源
    最近更新 更多