北单实体店主

量化岗测试问题与解答系列 | 第二十二期-Last ball

北单实体店主微信:av616X4

一个包有20个蓝色的球和14个红色的球,每次你随机拿出两个球。(假设包中的每个球被拿走的概率相等)。你不能把这两个球放回去,相反,如果两个球颜色相同,你添加一个蓝色的球到袋子;如果它们有不同的颜色,你添加一个红色的球到袋子里。假设你有无限量的蓝色和红色球,如果你继续重复这个过程,袋子里最后一个球的颜色是什么?如果袋子里有20个蓝球和13个红球呢?

解决方案:

一旦你理解了提示,这个问题应该很容易解决。让(B,R)表示包中蓝色球和红色球的数量,我们可以看看两个球出局后会发生什么。

两个球都是蓝色的:(B,R)-(B-1,R)

两个球都是红色的:(B,R)-(B+1,R-2)

一个红色和一个蓝色:(B,R)-(B-1,R)

蓝球漏气怎么办_蓝球_蓝球技术

注意,R要么保持不变,要么减少2,因此如果我们从14个红球开始,红球的数量永远不会变为奇数。我们也知道每次球的总数减少一个,直到只剩下一个球。结合我们掌握的信息,最后一个球一定是蓝色的。同样,当我们以奇数个红色球开始时,最后一个球必须是红色球。

Last ball

A bag has 20 blue balls and 14 red balls. Each time you randomly take two balls out. (Assume each ball in the bag has equal probability of being taken). You do not put these two balls back. Instead, if both balls have the same color, you add a blue ball to the bag; if they have different colors, you add a red ball to the bag. Assume that you have an unlimited supply of blue and red balls if you keep on repeating this process, what will be the color of the last ball left in the bag? What if the bag has 20 blue balls and 13 red balls instead?

Solution: Once you understand the hint, this problem should be an easy one. Let (B,R) represent the number of blue balls and red balls in the bag. We can take a look what will happen after two balls are taken out.

Both balls are blue: (B,R)-(B-1,R)

Both balls are red: (B,R)-(B+1,R-2)

One red and one blue: (B,R)-(B-1,R)

Notice that R either stays the same or decreases by 2, so the number of red balls will never become odd if we begin with 14 red balls. We also know that the total number of balls decreases by one each time until only one ball is left. Combining the information we have, the last ball must be a blue one. Similarly, when we start with odd number of red balls, the final ball must be a red one.

北单在那里买请加店主微信:av616X4