1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/移动石子直到连续 [moving-stones-until-consecutive].html
2022-03-29 12:43:11 +08:00

37 lines
1.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>a</code><code>b</code><code>c</code></p>
<p>每一回合,你可以从两端之一拿起一枚石子(位置最大或最小),并将其放入两端之间的任一空闲位置。形式上,假设这三枚石子当前分别位于位置 <code>x, y, z</code><code>x < y < z</code>。那么就可以从位置 <code>x</code> 或者是位置 <code>z</code> 拿起一枚石子,并将该石子移动到某一整数位置 <code>k</code> 处,其中 <code>x < k < z</code><code>k != y</code></p>
<p>当你无法进行任何移动时,即,这些石子的位置连续时,游戏结束。</p>
<p>要使游戏结束,你可以执行的最小和最大移动次数分别是多少? 以长度为 2 的数组形式返回答案:<code>answer = [minimum_moves, maximum_moves]</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>a = 1, b = 2, c = 5
<strong>输出:</strong>[1, 2]
<strong>解释:</strong>将石子从 5 移动到 4 再移动到 3或者我们可以直接将石子移动到 3。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>a = 4, b = 3, c = 2
<strong>输出:</strong>[0, 0]
<strong>解释:</strong>我们无法进行任何移动。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ol>
<li><code>1 <= a <= 100</code></li>
<li><code>1 <= b <= 100</code></li>
<li><code>1 <= c <= 100</code></li>
<li><code>a != b, b != c, c != a</code></li>
</ol>