困难的算法:徽章平衡,数学分布

vin*_*nux 1 php algorithm math logic

我有一个非常有趣的问题,让我的头脑扭曲.我正在研究一个由用户和奖项组成的小型系统(称为徽章).根据以下标准,用户可以获得特殊徽章:10枚铜徽章,5枚银徽章和1枚金徽章.这很简单,但是,如果用户有8枚铜牌,7枚银色徽章和1枚金徽章,他可以使用他的2枚额外银徽章作为青铜徽章.

每当用户有可用的"更高"徽章进行分发时,就会发生这种情况.例如,如果他有8枚青铜徽章,4枚银徽章和4枚金徽章,他可以将其2枚金徽章"变换"成青铜色,1枚变为银币,以获得特殊徽章.

我完全不知道该怎么做.我尝试过各种循环,ifs,但我永远不能正确分发.也许有人可以帮助我?

Kir*_*rst 5

用户需要至少1枚金徽章,至少6枚银色或金色徽章,以及至少16枚青铜,银色或金色徽章.

伪代码是

count(gold) >= 1
&& count(gold) + count(silver) >= 6
&& count(gold) + count(silver) + count(bronze) >= 16
Run Code Online (Sandbox Code Playgroud)

如果你还有一枚可以换取金,银或铜牌的钻石奖章,那么也包括它

count(diamond) + count(gold) >= 1
&& count(diamond) + count(gold) + count(silver) >= 6
// etc
Run Code Online (Sandbox Code Playgroud)

或者你可以使用'奖牌等级',这样你就可以做一些更简单的事情

count(rank of gold or higher) >= 1
&& count(rank of silver or higher) >= 6
&& count(rank of bronze or higher) >= 16
Run Code Online (Sandbox Code Playgroud)