EbowTang的练习场

1,新手需要努力,高手更需要努力。2,性格大于能力。3，解决问题的能力决定未来。...

<LeetCode OJ> 292. Nim Game

Total Accepted: 55175 Total Submissions: 105975 Difficulty: Easy

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.

Hint:

1. If there are 5 stones in the heap, could you figure out a way to remove the stones such that you will always be the winner?

8个，也就是两个4，我无论怎么摸石头都能让对手以4为一个坎最后摸完石头，所以必输

class Solution {
public:
bool canWinNim(int n) {
return n%4!=0;//卧槽，此题代码可以如此简单，意义何在？
}
};

LeetCode（292） Nim Game

2015-11-27 15:58:30

LeetCode292——Nim Game(一行代码解决)

2015-10-20 23:58:46

[LeetCode 292] Nim Game

2015-10-13 13:16:54

292. Nim Game [easy] (Python)

2016-05-10 17:17:39

[leetcode-292]Nim Game(java)

2015-10-13 14:46:56

LeetCode 292: Nim Game (Nim游戏)

2015-11-20 19:36:06

【LeetCode从零单刷】Nim Game

2015-10-13 16:42:16

【LeetCode-292】 Nim Game（C++）

2015-11-15 16:04:25

LeetCode 292. Nim Game 题解（C++）

2016-09-27 20:28:05

292. Nim Game LeetCode

2016-02-10 11:47:52