1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-12 17:05:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2025-09-29 14:43:44 +08:00
parent 2862a227c4
commit 13f2098086
4409 changed files with 168933 additions and 166256 deletions

View File

@@ -1,26 +1,33 @@
<p>&nbsp;<strong>A&nbsp;&nbsp;B 两种类型&nbsp;</strong>的汤。一开始每种类型的汤有&nbsp;<code>n</code>&nbsp;毫升。有四种分配操作</p>
<p>你有两种汤,<strong>A</strong><strong>B</strong>,每种初始为 <code>n</code>&nbsp;毫升。在每一轮中,会随机选择以下四种操作中的一种,每种操作的概率为 <code>0.25</code>,且与之前的所有轮次 <strong>无关</strong></p>
<ol>
<li>提供 <code>100ml</code><strong>汤A</strong><code>0ml</code><strong>汤B</strong></li>
<li>提供 <code>75ml</code><strong>汤A</strong><code>25ml</code><strong>汤B</strong></li>
<li>提供 <code>50ml</code><strong>汤A</strong><code>50ml</code><strong>汤B</strong></li>
<li>提供 <code>25ml</code><strong>汤A</strong><code>75ml</code><strong>汤B</strong></li>
<li>从汤 A 取 100 毫升,从汤 B 取 0 毫升</li>
<li>从汤 A 取 75 毫升,从汤 B 取 25 毫升</li>
<li>从汤 A 取 50 毫升,从汤 B 取 50 毫升</li>
<li>从汤 A 取 25 毫升,从汤 B 取 75 毫升</li>
</ol>
<p>当我们把汤分配给某人之后,汤就没有了。每个回合,我们将从四种概率同为 <code>0.25</code> 的操作中进行分配选择。如果汤的剩余量不足以完成某次操作,我们将尽可能分配。当两种类型的汤都分配完时,停止操作。</p>
<p><strong>注意:</strong></p>
<p><strong>注意&nbsp;</strong>不存在先分配 <code>100</code> ml <strong>汤B</strong> 的操作。</p>
<ul>
<li>不存在从汤 A 取&nbsp;<code>0</code>&nbsp;ml 和从汤 B 取&nbsp;<code>100</code> ml 的操作。</li>
<li>汤 A 和 B 在每次操作中同时被取出。</li>
<li>如果一次操作要求你取出比剩余的汤更多的量,请取出该汤剩余的所有部分。</li>
</ul>
<p>需要返回的值:&nbsp;<strong>汤A&nbsp;</strong>先分配完的概率 +&nbsp;&nbsp;<strong>汤A和汤B&nbsp;</strong>同时分配完的概率 / 2。返回值在正确答案&nbsp;<code>10<sup>-5</sup></code>&nbsp;的范围内将被认为是正确的</p>
<p>操作过程在任何回合中任一汤被取完后立即停止</p>
<p>返回汤 A 在 B 前取完的概率,加上两种汤在 <strong>同一回合&nbsp;</strong>取完概率的一半。返回值在正确答案&nbsp;<code>10<sup>-5</sup></code>&nbsp;的范围内将被认为是正确的。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong> n = 50
<strong>输出:</strong> 0.62500
<strong>解释:</strong>如果我们选择前两个操作<strong></strong>A 首先将变为空。
<strong>输入</strong>n = 50
<strong>输出</strong>0.62500
<strong>解释
</strong>如果我们选择前两个操作<strong></strong>A 首先将变为空。
对于第三个操作A 和 B 会同时变为空。
对于第四个操作B 首先将变为空。<strong>
</strong>所以 A 变为空的总概率加上 A 和 B 同时变为空的概率的一半是 0.25 *(1 + 1 + 0.5 + 0)= 0.625。
@@ -29,8 +36,14 @@
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong> n = 100
<strong>输出:</strong> 0.71875
<strong>输入</strong>n = 100
<strong>输出</strong>0.71875
<strong>解释:</strong>
如果我们选择第一个操作A 首先将变为空。
如果我们选择第二个操作A 将在执行操作 [1, 2, 3] 时变为空,然后 A 和 B 在执行操作 4 时同时变空。
如果我们选择第三个操作A 将在执行操作 [1, 2] 时变为空,然后 A 和 B 在执行操作 3 时同时变空。
如果我们选择第四个操作A 将在执行操作 1 时变为空,然后 A 和 B 在执行操作 2 时同时变空。
所以 A 变为空的总概率加上 A 和 B 同时变为空的概率的一半是 0.71875。
</pre>
<p>&nbsp;</p>