题目:

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.

Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.

代码:

 class Solution {
public:
bool canWinNim(int n) {
return (n% != );
}
};

LeetCode: 292 Nim Game(easy)的更多相关文章

  1. LN : leetcode 292 Nim Game

    lc 292 Nim Game 292 Nim Game You are playing the following Nim Game with your friend: There is a hea ...

  2. lintcode 394. Coins in a Line 、leetcode 292. Nim Game 、lintcode 395. Coins in a Line II

    变型:如果是最后拿走所有石子那个人输,则f[0] = true 394. Coins in a Line dp[n]表示n个石子,先手的人,是必胜还是必输.拿1个石子,2个石子之后都是必胜,则当前必败 ...

  3. Java实现 LeetCode 292 Nim游戏

    292. Nim 游戏 你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解 ...

  4. LeetCode 292. Nim Game (取物游戏)

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  5. LeetCode 292. Nim Game

    Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...

  6. Java [Leetcode 292]Nim Game

    问题描述: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl ...

  7. 【算法功底】LeetCode 292 Nim Game

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  8. 292. Nim Game(easy)

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  9. LeetCode 292 Nim Game 解题报告

    题目要求 You are playing the following Nim Game with your friend: There is a heap of stones on the table ...

随机推荐

  1. Active Directory组织单位(Organizational Unit)操作汇总

    前言 本章聊Active Directory的组织单位(OU)的新增.修改.移动等操作,使用.NET Framework 为我们提供的System.DirectoryServices程序集. 不积跬步 ...

  2. [Cocoa]深入浅出Cocoa之Bonjour网络编程

    本文转载至 http://www.cnblogs.com/kesalin/archive/2011/09/15/cocoa_bonjour.html   深入浅出Cocoa之Bonjour网络编程 罗 ...

  3. EasyDarwin开源社区 短视频拍摄项目Github地址

    在前面的几篇博客中,我们提到了EasyDarwin开源团队整理出来的短视频拍摄技术要点,这次我们将短视频技术及SDK整理成一个完整的Github项目进行长期维护,同时会支持安卓Android和IOS版 ...

  4. less 一种 动态 样式 语言

    LESS « 一种动态样式语言 http://www.bootcss.com/p/lesscss/ 一种 动态 样式 语言. LESS 将 CSS 赋予了动态语言的特性,如 变量, 继承,运算, 函数 ...

  5. 6 Maven聚合与集成

    Maven的聚合特性能够把项目的各个模块聚合在一起构件,而Maven的继承特性能够帮助抽取各个模块相同的依赖和插件等配置,简化POM的同时,还能促进各个模块配置的一致性.     1.聚合     为 ...

  6. xcode环境变量设置(转载)

    一般我们在xcode里面配置包含工程目录下头文件的时候,都要关联着相对路径和绝对路径,如果只是自己用这个项目,用绝对路径的问题不大,但是如果你把工程发给别人,别人就要在改这个绝对路径,这时候绝对路径的 ...

  7. [bzoj 3720] Gty的妹子树 (树上分块)

    树上分块(块状树) Description 我曾在弦歌之中听过你, 檀板声碎,半出折子戏. 舞榭歌台被风吹去, 岁月深处尚有余音一缕-- Gty神(xian)犇(chong)从来不缺妹子-- 他来到了 ...

  8. Bestcoder round 18---A题(素数筛+素数打表+找三个素数其和==n)

    Primes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. STL版 括号匹配(感觉不如之前自己用数组模拟的跑的快)

    数据结构实验之栈四:括号匹配 Time Limit: 1000MS Memory limit: 65536K 题目描述  给你一串字符,不超过50个字符,可能包括括号.数字.字母.标点符号.空格,你的 ...

  10. C语言中的排序算法--冒泡排序,选择排序,希尔排序

    冒泡排序(Bubble Sort,台湾译为:泡沫排序或气泡排序)是一种简单的排序算法.它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工作是重复地进行直到没 ...