码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode - Easy

时间:2016-01-27 02:00:39      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

@ 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的倍数时,必败;

Leetcode - Easy

标签:

原文地址:http://www.cnblogs.com/tanfy/p/leetcode-easy.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!