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.

/*
1: 赢
2: 赢
3: 赢
4: 不赢
5: 赢
6: 赢
7: 赢
8: 不赢
*/
class Solution {
public:
bool canWinNim(int n) {
if (n % == ){
return false;
}else{
return true;
}
}
};

好像很简单的样子。。

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

  1. LeetCode: 292 Nim Game(easy)

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

  2. 292. Nim Game

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

  3. 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 ...

  4. 292. Nim Game(C++)

    292. Nim Game(C++) You are playing the following Nim Game with your friend: There is a heap of stone ...

  5. LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers

    344. Reverse String /** * @param {string} s * @return {string} */ var reverseString = function(s) { ...

  6. 【Leetcode】292. Nim Game

    problem 292. Nim Game solution class Solution { public: bool canWinNim(int n) { ; } }; 来generalize一下 ...

  7. 292. Nim游戏

    292. Nim游戏 class Solution(object): def canWinNim(self, n): """ :type n: int :rtype: b ...

  8. 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个石子之后都是必胜,则当前必败 ...

  9. Java实现 LeetCode 292 Nim游戏

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

随机推荐

  1. javascript sort 函数用法

    sort 函数 博客地址:https://ainyi.com/41 简单的说,sort() 在没有参数时,返回的结果是按升序来排列的.即字符串的Unicode码位点(code point)排序 [5, ...

  2. 【.NET Core项目实战-统一认证平台】第十二章 授权篇-深入理解JWT生成及验证流程

    [.NET Core项目实战-统一认证平台]开篇及目录索引 上篇文章介绍了基于Ids4密码授权模式,从使用场景.原理分析.自定义帐户体系集成完整的介绍了密码授权模式的内容,并最后给出了三个思考问题,本 ...

  3. C# 常用小点

    1]创建文件夹 //相对路径 string FilePath = Server.MapPath("./") + "ImageFile/Images/" + Da ...

  4. MySQL 笔记整理(5) --深入浅出索引(下)

    笔记记录自林晓斌(丁奇)老师的<MySQL实战45讲> 5) --深入浅出索引(下) 这次的笔记从一个简单的查询开始: 建表语句是这样的 mysql> create table T ...

  5. JS输入框去除负号(限定输入正数)

    onkeyup="(this.v=function(){this.value=this.value.replace(/\-/g,\'\');}).call(this)" 示例: & ...

  6. mybatis基础(上)

    框架图 SqlSessionFactoryBuilder 通过SqlSessionFactoryBuilder创建会话工厂SqlSessionFactory 将SqlSessionFactoryBui ...

  7. 面试题之(HTTP协议)【转】

    转自:http://www.cnblogs.com/ranyonsue/p/5984001.html HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协 ...

  8. vue的项目结构记录

    vue的项目结构 不知道大家有没这样的情况,面对刚配置好的脚手架,创建的文件不知道该放哪个文件下,导致后面开发一些文件不好找,不利于维护. 接下来我说说我项目中的一些文件: 首先是components ...

  9. 轻量级应用程序Dynamics 365 App for Outlook介绍

    摘要: 本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复273或者20180625可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyon ...

  10. LEDAPS1.3.0版本移植到windows平台----HuCsm云掩膜模块

    这个是2012年左右放在百度空间的,谁知百度空间关闭...转移到博客园. 最近项目用到3.1.2版本的LEDAPS,新版本的使用情况会在后续文章中慢慢丰富. HuCsm是将LEDAPS项目中的TM/E ...