情侣期望数
Expected Couples
题目详情
来自四对已婚夫妇的八个人被随机分配到圆桌周围的座位。预计坐在一起的情侣数量是多少?
Eight people from four married couples are randomly assigned to seats around a round table. What is the expected number of couples that are seated next to each other?
解析
让我们来看看一位特定的女性。该女士旁边有 座位,她的丈夫随机坐在 剩余座位之一上。因此,女人坐在她丈夫旁边的概率是 。由于座位是随机分配的,因此没有女性坐在丈夫旁边的可能性不同,因此坐在丈夫旁边的女性(或夫妻总数)的预期数量是:
import random
couple_counts = []
num_iters = 100_000
for i in range(num_iters):
#where 1/2, 3/4, 5/6, and 7/8 are couples
people = [1, 2, 3, 4, 5, 6, 7, 8]
random.shuffle(people)
people.append(people[0])
num_couples = 0
for p in range(8):
if people[p] % 2 == 0:
if people[p] == people[p+1] + 1:
num_couples += 1
else:
if people[p] == people[p+1] -1:
num_couples += 1
couple_counts.append(num_couples)
#expecting 8/7 ~ 1.1429
print(sum(couple_counts) / num_iters)Original Explanation
Let's take a look at a given woman. There are seats adjacent to this woman and her husband is randomly seated in one of the remaining seats. Thus the probability the woman sits next to her husband is . Since seating is assigned at random, no woman has a different likelihood to be seated next to her husband and so the expected number of woman that sit next to their husband (or total couples is):
import random
couple_counts = []
num_iters = 100_000
for i in range(num_iters):
#where 1/2, 3/4, 5/6, and 7/8 are couples
people = [1, 2, 3, 4, 5, 6, 7, 8]
random.shuffle(people)
people.append(people[0])
num_couples = 0
for p in range(8):
if people[p] % 2 == 0:
if people[p] == people[p+1] + 1:
num_couples += 1
else:
if people[p] == people[p+1] -1:
num_couples += 1
couple_counts.append(num_couples)
#expecting 8/7 ~ 1.1429
print(sum(couple_counts) / num_iters)