返回题库

偶数先于奇数

Even Before Odd

专题
Probability / 概率
难度
L4

题目详情

假设你掷出一个 6 面骰子,直到你看到所有 6 个面为止。在你看到所有偶数面之前,你看不到奇数面的概率是多少?

Suppose you roll a fair 6-sided die until you've seen all 6 faces. What is the probability you won't see an odd numbered face until you have seen all even numbered faces?

解析

重要的是要认识到,在这个问题中,你不应该关注掷骰子的数量,而应该关注看到面时的排序方式。也就是说,序列 2,5,3,1,4,62,5,3,1,4,6 代表你的第一个独特次见到是 22,第二个是 55,第三个是 33,依此类推。这将是一个无效的序列,因为我们在看到所有偶数编号的面之前已经看到了奇数编号的面。

总订购量为 6!6!。我们可以用它作为我们的分母。

对于我们的分子,我们希望仅对第一个 33 次出现的偶数进行分组,对最后一个 33 的剩余奇数进行分组。

3!3! 方法对奇数进行排序,以及 3!3! 方法对偶数进行排序。

3!3!6!=66720=120\begin{equation*} \frac{3!3!}{6!} = \frac{6\cdot6}{720} = \boxed{\frac1{20}} \end{equation*}
import random

roll_dice = lambda: random.randint(1, 6)

valid_cases = 0
num_iters = 100_000
for i in range(num_iters):

    seen_faces = set()
    while(True):

        roll = roll_dice()
        seen_faces.add(roll)

        if roll % 2 == 1 and len(seen_faces) < 4:
            break

        if len(seen_faces) == 6:
            valid_cases += 1
            break

print(valid_cases / num_iters)

Original Explanation

It's important to realize that you should not focus on the number of rolls in this question, but rather the ways to order when a face has been seen. ie) The sequence 2,5,3,1,4,62,5,3,1,4,6 represents your first unique sighting being a 22, second being a 55, third being 33, and so on. This would be an invalid sequence as we have seen an odd numbered face before seeing all the even numbered faces.

There are 6!6! total orderings. We can use this as our denominator.

For our numerator, we want to group only even numbers for the first 33 sightings, and the remaining odd numbers for the last 33.

There are 3!3! ways to order the odd numbers as well as 3!3! ways to order the even numbers.

3!3!6!=66720=120\begin{equation*} \frac{3!3!}{6!} = \frac{6\cdot6}{720} = \boxed{\frac1{20}} \end{equation*}
import random

roll_dice = lambda: random.randint(1, 6)

valid_cases = 0
num_iters = 100_000
for i in range(num_iters):

    seen_faces = set()
    while(True):

        roll = roll_dice()
        seen_faces.add(roll)

        if roll % 2 == 1 and len(seen_faces) < 4:
            break

        if len(seen_faces) == 6:
            valid_cases += 1
            break

print(valid_cases / num_iters)