-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNim 游戏 [nim-game].html
46 lines (34 loc) · 1.5 KB
/
Nim 游戏 [nim-game].html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<p>你和你的朋友,两个人一起玩 <a href="https://baike.baidu.com/item/Nim游戏/6737105" target="_blank">Nim 游戏</a>:</p>
<ul>
<li>桌子上有一堆石头。</li>
<li>你们轮流进行自己的回合, <strong>你作为先手 </strong>。</li>
<li>每一回合,轮到的人拿掉 1 - 3 块石头。</li>
<li>拿掉最后一块石头的人就是获胜者。</li>
</ul>
<p>假设你们每一步都是最优解。请编写一个函数,来判断你是否可以在给定石头数量为 <code>n</code> 的情况下赢得游戏。如果可以赢,返回 <code>true</code>;否则,返回 <code>false</code> 。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong><code>n = 4</code>
<strong>输出:</strong>false
<strong>解释:</strong>以下是可能的结果:
1. 移除1颗石头。你的朋友移走了3块石头,包括最后一块。你的朋友赢了。
2. 移除2个石子。你的朋友移走2块石头,包括最后一块。你的朋友赢了。
3.你移走3颗石子。你的朋友移走了最后一块石头。你的朋友赢了。
在所有结果中,你的朋友是赢家。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>n = 1
<strong>输出:</strong>true
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>n = 2
<strong>输出:</strong>true
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= n <= 2<sup>31</sup> - 1</code></li>
</ul>