mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 02:41:42 +08:00
批量更新数据
This commit is contained in:
@@ -1,41 +1,57 @@
|
||||
<p>You are given two jugs with capacities <code>jug1Capacity</code> and <code>jug2Capacity</code> liters. There is an infinite amount of water supply available. Determine whether it is possible to measure exactly <code>targetCapacity</code> liters using these two jugs.</p>
|
||||
|
||||
<p>If <code>targetCapacity</code> liters of water are measurable, you must have <code>targetCapacity</code> liters of water contained <strong>within one or both buckets</strong> by the end.</p>
|
||||
|
||||
<p>Operations allowed:</p>
|
||||
<p>You are given two jugs with capacities <code>x</code> liters and <code>y</code> liters. You have an infinite water supply. Return whether the total amount of water in both jugs may reach <code>target</code> using the following operations:</p>
|
||||
|
||||
<ul>
|
||||
<li>Fill any of the jugs with water.</li>
|
||||
<li>Empty any of the jugs.</li>
|
||||
<li>Pour water from one jug into another till the other jug is completely full, or the first jug itself is empty.</li>
|
||||
<li>Fill either jug completely with water.</li>
|
||||
<li>Completely empty either jug.</li>
|
||||
<li>Pour water from one jug into another until the receiving jug is full, or the transferring jug is empty.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1: </strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> jug1Capacity = 3, jug2Capacity = 5, targetCapacity = 4
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The famous <a href="https://www.youtube.com/watch?v=BVtQNK_ZUJg&ab_channel=notnek01" target="_blank">Die Hard</a> example
|
||||
</pre>
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p><strong>Input: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> x = 3, y = 5, target = 4 </span></p>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<p><strong>Output: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> true </span></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> jug1Capacity = 2, jug2Capacity = 6, targetCapacity = 5
|
||||
<strong>Output:</strong> false
|
||||
</pre>
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
<p>Follow these steps to reach a total of 4 liters:</p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> jug1Capacity = 1, jug2Capacity = 2, targetCapacity = 3
|
||||
<strong>Output:</strong> true
|
||||
</pre>
|
||||
<ol>
|
||||
<li>Fill the 5-liter jug (0, 5).</li>
|
||||
<li>Pour from the 5-liter jug into the 3-liter jug, leaving 2 liters (3, 2).</li>
|
||||
<li>Empty the 3-liter jug (0, 2).</li>
|
||||
<li>Transfer the 2 liters from the 5-liter jug to the 3-liter jug (2, 0).</li>
|
||||
<li>Fill the 5-liter jug again (2, 5).</li>
|
||||
<li>Pour from the 5-liter jug into the 3-liter jug until the 3-liter jug is full. This leaves 4 liters in the 5-liter jug (3, 4).</li>
|
||||
<li>Empty the 3-liter jug. Now, you have exactly 4 liters in the 5-liter jug (0, 4).</li>
|
||||
</ol>
|
||||
|
||||
<p>Reference: The <a href="https://www.youtube.com/watch?v=BVtQNK_ZUJg&ab_channel=notnek01" target="_blank">Die Hard</a> example.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2: </strong></p>
|
||||
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p><strong>Input: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> x = 2, y = 6, target = 5 </span></p>
|
||||
|
||||
<p><strong>Output: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> false </span></p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3: </strong></p>
|
||||
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p><strong>Input: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> x = 1, y = 2, target = 3 </span></p>
|
||||
|
||||
<p><strong>Output: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> true </span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> Fill both jugs. The total amount of water in both jugs is equal to 3 now.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= jug1Capacity, jug2Capacity, targetCapacity <= 10<sup>6</sup></code></li>
|
||||
<li><code>1 <= x, y, target <= 10<sup>3</sup></code></li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user