通过巧克力的轮次数

时间:2013-03-30 18:35:19

标签: algorithm combinatorics

我们正在玩一个有n个孩子坐在一个圆圈里的游戏。他们每个人都有一些巧克力。巧克力的总数是这样的,它们可以在所有儿童中平均分配。

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

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

我们应该采用什么算法?

1 个答案:

答案 0 :(得分:0)

我的启发式将是:

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)