mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 10:51:42 +08:00
批量更新数据
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
<p>你的初始 <strong>能量</strong> 为 <code>power</code>,初始 <strong>分数</strong> 为 <code>0</code>,只有一包令牌 <code>tokens</code> 。其中 <code>tokens[i]</code> 是第 <code>i</code> 个令牌的值(下标从 0 开始)。</p>
|
||||
<p>你的初始 <strong>能量</strong> 为 <code>power</code>,初始 <strong>分数</strong> 为 <code>0</code>,只有一包令牌以整数数组 <code>tokens</code> 给出。其中 <code>tokens[i]</code> 是第 <code>i</code> 个令牌的值(下标从 0 开始)。</p>
|
||||
|
||||
<p>令牌可能的两种使用方法如下:</p>
|
||||
<p>你的目标是通过有策略地使用这些令牌以 <strong>最大化</strong> 总 <strong>分数</strong>。在一次行动中,你可以用两种方式中的一种来使用一个 <strong>未被使用的</strong> 令牌(但不是对同一个令牌使用两种方式):</p>
|
||||
|
||||
<ul>
|
||||
<li>如果你至少有 <code>token[i]</code> 点 <strong>能量</strong> ,可以将令牌 <code>i</code> 置为正面朝上,失去 <code>token[i]</code> 点 <strong>能量</strong> ,并得到 <code>1</code> <strong>分</strong> 。</li>
|
||||
<li>如果我们至少有 <code>1</code> <strong>分 </strong>,可以将令牌 <code>i</code> 置为反面朝上,获得 <code>token[i]</code> 点 <strong>能量</strong> ,并失去 <code>1</code> <strong>分</strong> 。</li>
|
||||
<li><strong>朝上</strong>:如果你当前 <strong>至少</strong> 有 <code>tokens[i]</code> 点 <strong>能量</strong> ,可以使用令牌 <code>i</code> ,失去 <code>tokens[i]</code> 点 <strong>能量</strong> ,并得到 <code>1</code> <strong>分</strong> 。</li>
|
||||
<li><strong>朝下</strong>:如果你当前至少有 <code>1</code> <strong>分 </strong>,可以使用令牌 <code>i</code> ,获得 <code>tokens[i]</code> 点 <strong>能量</strong> ,并失去 <code>1</code> <strong>分</strong> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>每个令牌 <strong>最多</strong> 只能使用一次,使用 <strong>顺序不限</strong> ,<strong>不需</strong> 使用所有令牌。</p>
|
||||
|
||||
<p>在使用任意数量的令牌后,返回我们可以得到的最大 <strong>分数</strong> 。</p>
|
||||
<p>在使用 <strong>任意</strong> 数量的令牌后,返回我们可以得到的最大 <strong>分数</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
@@ -21,15 +19,15 @@
|
||||
<pre>
|
||||
<strong>输入:</strong>tokens = [100], power = 50
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>无法使用唯一的令牌,因为能量和分数都太少了。</pre>
|
||||
<strong>解释:</strong>因为你的初始分数为 <code>0,</code>无法使令牌朝下。你也不能使令牌朝上因为你的能量(<code>50</code>)比 <code>tokens[0]</code> 少(<code>100</code>)。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>tokens = [100,200], power = 150
|
||||
<strong>输入:</strong>tokens = [200,100], power = 150
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>令牌 0 正面朝上,能量变为 50,分数变为 1 。
|
||||
不必使用令牌 1 ,因为你无法使用它来提高分数。</pre>
|
||||
<strong>解释:</strong>使令牌 1 正面朝上,能量变为 50,分数变为 1 。
|
||||
不必使用令牌 0,因为你无法使用它来提高分数。可得到的最大分数是 <code>1</code>。</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
@@ -37,10 +35,13 @@
|
||||
<strong>输入:</strong>tokens = [100,200,300,400], power = 200
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>按下面顺序使用令牌可以得到 2 分:
|
||||
1. 令牌 0 正面朝上,能量变为 100 ,分数变为 1
|
||||
2. 令牌 3 正面朝下,能量变为 500 ,分数变为 0
|
||||
3. 令牌 1 正面朝上,能量变为 300 ,分数变为 1
|
||||
4. 令牌 2 正面朝上,能量变为 0 ,分数变为 2</pre>
|
||||
1. 令牌 0 (<code>100</code>)正面朝上,能量变为 <code>100</code> ,分数变为 <code>1</code>
|
||||
2. 令牌 3 (<code>400</code>)正面朝下,能量变为 <code>500</code> ,分数变为 <code>0</code>
|
||||
3. 令牌 1 (<code>200</code>)正面朝上,能量变为 <code>300</code> ,分数变为 <code>1</code>
|
||||
4. 令牌 2 (<code>300</code>)正面朝上,能量变为 <code>0</code> ,分数变为 <code>2</code>
|
||||
|
||||
可得的最大分数是 2。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
Reference in New Issue
Block a user