标签:
@ 292 Nim Game
code:
1 class Solution { 2 public: 3 bool canWinNim(int n) 4 { 5 return 0!=(n%4); 6 } 7 };
submition detail:
thought:
当为4个时,必败;
当为8个时,我只能取1/2/3,使方块数目剩余7/6/5给对方,对方取时将会剩余4个给我,必败;
当为12个时,我只能取1/2/3,使方块数目剩余11/10/9给对方,对方取时将会剩余8个给我,必败;
依次类推=》当方块数目为4的倍数时,必败;
标签:
原文地址:http://www.cnblogs.com/tanfy/p/leetcode-easy.html