mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			33 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine which bucket is poisonous.</p>
 | 
						|
 | 
						|
<p>You can feed the pigs according to these steps:</p>
 | 
						|
 | 
						|
<ol>
 | 
						|
	<li>Choose some live pigs to feed.</li>
 | 
						|
	<li>For each pig, choose which buckets to feed it. The pig will consume all the chosen buckets simultaneously and will take no time.</li>
 | 
						|
	<li>Wait for <code>minutesToDie</code> minutes. You may <strong>not</strong> feed any other pigs during this time.</li>
 | 
						|
	<li>After <code>minutesToDie</code> minutes have passed, any pigs that have been fed the poisonous bucket will die, and all others will survive.</li>
 | 
						|
	<li>Repeat this process until you run out of time.</li>
 | 
						|
</ol>
 | 
						|
 | 
						|
<p>Given <code>buckets</code>, <code>minutesToDie</code>, and <code>minutesToTest</code>, return <em>the <strong>minimum</strong> number of pigs needed to figure out which bucket is poisonous within the allotted time</em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Example 1:</strong></p>
 | 
						|
<pre><strong>Input:</strong> buckets = 1000, minutesToDie = 15, minutesToTest = 60
 | 
						|
<strong>Output:</strong> 5
 | 
						|
</pre><p><strong>Example 2:</strong></p>
 | 
						|
<pre><strong>Input:</strong> buckets = 4, minutesToDie = 15, minutesToTest = 15
 | 
						|
<strong>Output:</strong> 2
 | 
						|
</pre><p><strong>Example 3:</strong></p>
 | 
						|
<pre><strong>Input:</strong> buckets = 4, minutesToDie = 15, minutesToTest = 30
 | 
						|
<strong>Output:</strong> 2
 | 
						|
</pre>
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= buckets <= 1000</code></li>
 | 
						|
	<li><code>1 <= minutesToDie <= minutesToTest <= 100</code></li>
 | 
						|
</ul>
 |