1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/可怜的小猪 [poor-pigs].html
2022-03-29 12:43:11 +08:00

46 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p><code> buckets</code> 桶液体,其中 <strong>正好有一桶</strong>&nbsp;含有毒药,其余装的都是水。它们从外观看起来都一样。为了弄清楚哪只水桶含有毒药,你可以喂一些猪喝,通过观察猪是否会死进行判断。不幸的是,你只有&nbsp;<code>minutesToTest</code> 分钟时间来确定哪桶液体是有毒的。</p>
<p>喂猪的规则如下:</p>
<ol>
<li>选择若干活猪进行喂养</li>
<li>可以允许小猪同时饮用任意数量的桶中的水,并且该过程不需要时间。</li>
<li>小猪喝完水后,必须有 <code>minutesToDie</code> 分钟的冷却时间。在这段时间里,你只能观察,而不允许继续喂猪。</li>
<li>过了 <code>minutesToDie</code> 分钟后,所有喝到毒药的猪都会死去,其他所有猪都会活下来。</li>
<li>重复这一过程,直到时间用完。</li>
</ol>
<p>给你桶的数目 <code>buckets</code> <code>minutesToDie</code><code>minutesToTest</code> ,返回&nbsp;<em>在规定时间内判断哪个桶有毒所需的 <strong>最小</strong> 猪数</em>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>buckets = 1000, minutesToDie = 15, minutesToTest = 60
<strong>输出:</strong>5
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>buckets = 4, minutesToDie = 15, minutesToTest = 15
<strong>输出:</strong>2
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>buckets = 4, minutesToDie = 15, minutesToTest = 30
<strong>输出:</strong>2
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= buckets &lt;= 1000</code></li>
<li><code>1 &lt;=&nbsp;minutesToDie &lt;=&nbsp;minutesToTest &lt;= 100</code></li>
</ul>