## Nim Game 原

叶枫啦啦

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.

Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.

For example, if there are 4 stones in the heap, then you will never win the game: no matter 1, 2, or 3 stones you remove, the last stone will always be removed by your friend.

【注】题目给定一堆石子，每次可以拿一个两个或三个，两个人轮流拿，拿到最后一个石子的人获胜，现在给我们一堆石子的个数，问我们能不能赢。那么我们就从最开始分析，由于是我们先拿，那么3个以内(包括3个)的石子，我们直接赢，如果共4个，那么我们一定输，因为不管我们取几个，下一个人一次都能取完。如果共5个，我们赢，因为我们可以取一个，然后变成4个让别人取，根据上面的分析我们赢，所以我们列出1到10个的情况如下：

1    Win
2    Win
3    Win
4    Lost
5    Win
6    Win
7    Win
8    Lost
9    Win
10   Win

① 对4取余，如果==0就输了。

class Solution { //0ms
public boolean canWinNim(int n) {
return n % 4 == 0 ? false : true;
}
}

### 叶枫啦啦

LeetCode：Nim Game - 尼姆博弈

1、题目名称 Nim Game（尼姆博弈） 2、题目地址 https://leetcode.com/problems/nim-game/ 3、题目内容 英文： You are playing the following Nim Game with your friend: There is a heap......

2015/12/20
263
0
292. Nim Game - LeetCode

Question 292. Nim Game Solution 思路：试着列举一下，就能发现一个n只要不是4的倍数，就能赢。 Java实现：

yysue
2018/06/25
0
0
Nim Game(leetcode292)

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the......

woshixin
2018/12/17
0
0
leetcode- nim game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the......

2016/07/15
4
0
HDU 6237/2017CCPC哈尔滨 A Simple Stone Game【质因子】

A Simple Stone Game Time Limit: 2000/1000 MS(Java/Others) Memory Limit: 262144/262144 K(Java/Others) Total Submission(s): 524 Accepted Submission(s): 107 Problem Description Aft......

my_sunshine26
2017/11/12
0
0

NIO基于长度域的报文在Netty下的解码

1, 先复习一下粘包/拆包 1.1, 粘包/拆包的含义 TCP是个“流”协议, 并不了解上层业务数据的具体含义, 它会根据TCP缓冲区的实际情况进行包的划分，所以在业务上认为，一个完整的包可能会被TCP...

8
0

Vincent-Duan

19
0
get和post的区别？

doGet：路径传参。效率高，安全性差（get的传送数据量有限制，不能大于2Kb） doPOST：实体传参。效率低，安全性好 建议： 1、get方式的安全性较Post方式要差些，包含机密信息的话，建议用Pos...

4
0

14
0
10天学Python直接做项目，我做了这5件事

Python派森

7
0