返回题库

正面更多

More Heads

专题
Probability / 概率
难度
L8

题目详情

爱丽丝和鲍勃各有一枚硬币,并翻转它,直到得到正面。如果鲍勃抛硬币的次数比爱丽丝多,那么爱丽丝抛硬币的预期次数是多少?

Alice and Bob each have a coin and flip it until they get a heads. If Bob flipped his coin more times than Alice, what is the expected number of times Alice flipped her coin?

解析

让我们将 AA 表示为 Alice 翻转硬币的次数,将 BB 表示为 Bob 翻转硬币的次数。我们给出了条件 A<BA < B。找到 P(A<B)P(A < B) 后,我们就可以形成条件期望。通过对称性 P(A<B)=P(B<A)P(A < B) = P(B < A),我们可以看到: P(A<B)=1P(A=B)2P(A < B) = \frac{1 - P(A =B)}2 有机会 1212\frac12\cdot\frac12 两个硬币都翻转一次,1414\frac14\cdot\frac14 两次,1818\frac18\cdot\frac18 三次,依此类推。因此, P(A=B)=14+116+164...P(A = B) = \frac14+\frac1{16}+\frac1{64}... 4P(A=B)=1+14+116+164...\rightarrow 4P(A = B) = 1 + \frac14+\frac1{16}+\frac1{64}... 从底部减去顶部我们可以看到: 3P(A=B)=13P(A = B) = 1 P(A=B)=13\rightarrow P(A = B) = \frac13 使用它我们计算: P(A<B)=1132=13P(A < B) = \frac{1 - \frac13}2 = \frac13 我们现在可以计算 P(A=nA<B)P(A = n | A < B)。如果爱丽丝抛硬币一次,我们知道她在第一次抛硬币时一定会得到正面,而鲍勃在第一次抛硬币时一定会得到反面。如果她掷硬币两次,她会得到正面,然后是反面,而鲍勃在前两次抛硬币时会得到反面,依此类推。我们的有条件期望: E[AA<B]=121213(1)+141413(2)+181813(3)...=34(1)+316(2)+364(3)...E[A | A < B] = \frac{\frac12\cdot\frac12}{\frac13}(1) + \frac{\frac14\cdot\frac14}{\frac13}(2) + \frac{\frac18\cdot\frac18}{\frac13}(3)... = \frac34(1) + \frac3{16}(2) + \frac3{64}(3)... =34(1)+316(2)+364(3)...= \frac34(1) + \frac3{16}(2) + \frac3{64}(3)... 我们可以将 4E[AA<B]E[AA<B]4E[A | A < B] - E[A | A < B] 计算为: 4E[AA<B]=3(1)+34(2)+316(3)+364(4)...4E[A | A < B] = 3(1) + \frac3{4}(2) + \frac3{16}(3) + \frac3{64}(4)... 4E[AA<B]E[AA<B]=3E[AA<B]=3+34+316+364...4E[A | A < B] - E[A | A < B] = 3E[A | A < B] = 3 + \frac34 + \frac3{16} + \frac3{64}... 同样我们计算: 12E[AA<B]=12+3+34+316+364...12E[A | A < B] = 12 + 3 + \frac34 + \frac3{16} + \frac3{64}... 12E[AA<B]3E[AA<B]=9E[AA<B]=1212E[A | A < B] - 3E[A | A < B] = 9E[A | A < B] = 12 E[AA<B]=43\Longrightarrow E[A | A < B] = \boxed{\frac43}

import random

flip_coin = lambda: True if random.randint(1,2) == 1 else False

alice_flip_counts = []
num_iters = 100_000
for i in range(num_iters):

    alice_flips = 0
    while(True):

        bob_flips_heads = flip_coin()
        if bob_flips_heads:
            break

        alice_flips += 1

        alice_flips_heads = flip_coin()
        if alice_flips_heads:
            alice_flip_counts.append(alice_flips)
            break

#expecting close to 4/3
print(sum(alice_flip_counts) / len(alice_flip_counts))

Original Explanation

Let's denote AA as the number of times Alice flips her coin and BB the number of times Bob flips his coin. We are given the condition A<BA < B. Upon finding P(A<B)P(A < B) we can form our conditional expectations. By symmetry P(A<B)=P(B<A)P(A < B) = P(B < A) so we see that: P(A<B)=1P(A=B)2P(A < B) = \frac{1 - P(A =B)}2 There is a 1212\frac12\cdot\frac12 chance both coins are flipped once, 1414\frac14\cdot\frac14 twice, 1818\frac18\cdot\frac18 three times and so on. Thus, P(A=B)=14+116+164...P(A = B) = \frac14+\frac1{16}+\frac1{64}... 4P(A=B)=1+14+116+164...\rightarrow 4P(A = B) = 1 + \frac14+\frac1{16}+\frac1{64}... Subtracting the top from bottom we see: 3P(A=B)=13P(A = B) = 1 P(A=B)=13\rightarrow P(A = B) = \frac13 Using this we compute: P(A<B)=1132=13P(A < B) = \frac{1 - \frac13}2 = \frac13

We can now compute P(A=nA<B)P(A = n | A < B). If Alice flips her coin once, we know that she must get a heads on the first flip and Bob must get a tails on his first flip. If she flips her coin twice, she gets a heads followed by tails and Bob gets tails for his first two flips and so on. Our conditional expectations: E[AA<B]=121213(1)+141413(2)+181813(3)...=34(1)+316(2)+364(3)...E[A | A < B] = \frac{\frac12\cdot\frac12}{\frac13}(1) + \frac{\frac14\cdot\frac14}{\frac13}(2) + \frac{\frac18\cdot\frac18}{\frac13}(3)... = \frac34(1) + \frac3{16}(2) + \frac3{64}(3)... =34(1)+316(2)+364(3)...= \frac34(1) + \frac3{16}(2) + \frac3{64}(3)...

We can compute 4E[AA<B]E[AA<B]4E[A | A < B] - E[A | A < B] as: 4E[AA<B]=3(1)+34(2)+316(3)+364(4)...4E[A | A < B] = 3(1) + \frac3{4}(2) + \frac3{16}(3) + \frac3{64}(4)... 4E[AA<B]E[AA<B]=3E[AA<B]=3+34+316+364...4E[A | A < B] - E[A | A < B] = 3E[A | A < B] = 3 + \frac34 + \frac3{16} + \frac3{64}... Similarly we compute: 12E[AA<B]=12+3+34+316+364...12E[A | A < B] = 12 + 3 + \frac34 + \frac3{16} + \frac3{64}... 12E[AA<B]3E[AA<B]=9E[AA<B]=1212E[A | A < B] - 3E[A | A < B] = 9E[A | A < B] = 12 E[AA<B]=43\Longrightarrow E[A | A < B] = \boxed{\frac43}

import random

flip_coin = lambda: True if random.randint(1,2) == 1 else False

alice_flip_counts = []
num_iters = 100_000
for i in range(num_iters):

    alice_flips = 0
    while(True):

        bob_flips_heads = flip_coin()
        if bob_flips_heads:
            break

        alice_flips += 1

        alice_flips_heads = flip_coin()
        if alice_flips_heads:
            alice_flip_counts.append(alice_flips)
            break

#expecting close to 4/3
print(sum(alice_flip_counts) / len(alice_flip_counts))