返回题库

三棒

Three Sticks

专题
Probability / 概率
难度
L5

题目详情

假设给你一根 1 米长的棍子。随机选择棍子上的 2 个点,并在这 2 个点处折断它,得到 3 块。最小的一块最多 0.2 米的概率是多少?

Assume you are given a stick that is 1 meter in length. Randomly select 2 points on the stick and break it at these 2 points to get 3 pieces. What's the probability that the smallest piece is at most 0.2 meter?

解析

我们可以先用一张图来说明木棍被分成三块的地方。我们将第一点表示为 x\textit{x},将第二点表示为 y\textit{y}。那么,这3个片段的给定长度为x\textit{x}y-x\textit{y-x}1-y\textit{1-y}。我们正在计算 P(min(x,yx,1y)0.2)P(min(x, y-x, 1-y) \leq 0.2)。这对应于3个片段中最小的一个或min(x, y-x, 1-y)\textit{min(x, y-x, 1-y)}的长度至多为0.2或小于或等于0.2的事件。

图片

解决此问题的第一个关键观察结果是认识到 P(min(x,yx,1y)<=0.2)P(min(x, y-x, 1-y) <= 0.2) 等于 1P(x,yx,1y0.2)1 - P(x, y-x, 1-y \geq 0.2)。这是根据补码规则。最小值事件上限的补集是所有事件都高于最小值的事件。这具有逻辑意义:最小值小于 0.2 的“相反”是所有值都高于 0.2。

我们现在可以这样直观地划分上述样本空间。我们从 1 x 1\textit{1 x 1} 网格开始,随机变量 x\textit{x}y\textit{y} 在各自的轴上。然后,我们沿着线 y=x\textit{y=x} 将这个空间分成两半,并将我们的结果空间限制在正方形的上半部分三角形。这是因为,通过指示 y 是两个点中的第二个点或 maximum\textit{maximum},我们将结果空间限制为仅具有 yxy \geq x 的点。

图片

图片

一旦我们定义了结果空间,我们就可以计算与事件 P(x,yx,1y>=0.2)P(x, y-x, 1-y >= 0.2) 对应的三角形的子区域。第一个条件是x0.2x \geq 0.2。我们可以对活动空间进行相应的分区和缩小。第二个条件是1y0.21-y \geq 0.2y0.8y \leq 0.8。我们可以再次相应地缩小活动空间。最后一个条件是yx0.2y-x \geq 0.2。然而,我们注意到剩余空间(白色的中心三角形)已经满足这个条件。所以我们需要计算这个三角形的面积:0.40.40.5=0.080.4*0.4*0.5 = 0.08。现在,我们将事件空间的面积除以结果空间的面积,我们在上面将结果空间定义为上半三角形,即 0.5:0.08/0.5=0.160.08 / 0.5 = 0.16

图片

现在请记住,需要该区域来计算所需事件的补码,因此从 1:10.161 - 0.16 中减去它,即可得到 P(min(x,yx,1y)0.2)=0.84P(min(x, y-x, 1-y) \leq 0.2) = 0.84

这是演示此解决方案的程序:

import random

def simulate_trial():
   x, y = random.uniform(0, 1), random.uniform(0, 1)
   x, y = min(x, y), max(x, y)
   sides = [x, y-x, 1-y]
   return min(sides)

res = []

for _ in range(1_000_000):
   val = simulate_trail()
   res.append(val)

print(len([i for i in res if i <= 0.2] / len(res)))

Original Explanation

We can start by illustrating a diagram indicating where the stick is broken into 3 pieces. We denote the first point as x\textit{x} and the second as y\textit{y}. Then, the given length of the 3 pieces is x\textit{x}, y-x\textit{y-x}, and 1-y\textit{1-y}. We are looking to calculate the P(min(x,yx,1y)0.2)P(min(x, y-x, 1-y) \leq 0.2). This corresponds to the event that the length of the smallest of the 3 pieces, or min(x, y-x, 1-y)\textit{min(x, y-x, 1-y)}, is at most 0.2, or less than or equal to 0.2.

Image

The first key observation to solving this problem is to recognize that P(min(x,yx,1y)<=0.2)P(min(x, y-x, 1-y) <= 0.2) is equal to 1P(x,yx,1y0.2)1 - P(x, y-x, 1-y \geq 0.2). This is by the complement rule. The complement to the event upper bounding the minimum, is the event that all are above the minimum. This makes logical sense: the ‘opposite’ of the minimum being less than 0.2 is for all to be above 0.2.

We can now partition the above sample space visually as such. We start with a 1 x 1\textit{1 x 1} grid, random variables x\textit{x} and y\textit{y} on their respective axes. We then partition this space in half along the line y=x\textit{y=x}, and restrict our outcome space to the upper half triangle of the square. This is because, by indicating that y is the second or maximum\textit{maximum} of the two points, we are restricting our outcome space to only points with yxy \geq x.

Image

Image

Once we’ve defined the outcome space, let’s compute the sub area of this triangle that corresponds to the event P(x,yx,1y>=0.2)P(x, y-x, 1-y >= 0.2). The first condition is that x0.2x \geq 0.2. We can partition and reduce the event space accordingly. The second condition is that 1y0.21-y \geq 0.2, or y0.8y \leq 0.8. We can reduce the event space accordingly again. The last condition is that yx0.2y-x \geq 0.2. However, we notice that the remaining space (the white, center triangle), already satisfies this condition. So we’re left to compute the area of this triangle: 0.40.40.5=0.080.4*0.4*0.5 = 0.08. We now divide the area of the event space, by the area of the outcome space, which we defined above to just be the upper half triangle, or 0.5: 0.08/0.5=0.160.08 / 0.5 = 0.16.

Image

Now remember that this area was needed to calculate the complement of the desired event, so subtract it from 1: 10.161 - 0.16, to get P(min(x,yx,1y)0.2)=0.84P(min(x, y-x, 1-y) \leq 0.2) = 0.84.

Here is a program demonstrating this solution:

import random

def simulate_trial():
   x, y = random.uniform(0, 1), random.uniform(0, 1)
   x, y = min(x, y), max(x, y)
   sides = [x, y-x, 1-y]
   return min(sides)

res = []

for _ in range(1_000_000):
   val = simulate_trail()
   res.append(val)

print(len([i for i in res if i <= 0.2] / len(res)))