Problem:
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 to 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 stones in the heap, then you will never win the game: no matter , , or stones you remove, the last stone will always be removed by your friend.

此题为技巧题,需知道Nim Game的Wining Strange,即在自己的局中,如果剩余数目为4的倍数,则不可能取胜。因此检测N是否为4的倍数即可。Background参见http://www.cdf.toronto.edu/~ajr/270/probsess/03/strategy.html

class Solution {
public:
bool canWinNim(int n) {
if(n% == ) return false;
else return true; }
};

LeetCode 292. Nim Game的更多相关文章

  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. Java [Leetcode 292]Nim Game

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

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

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

  7. LeetCode 292 Nim Game 解题报告

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

  8. LeetCode 292 Nim Game(Nim游戏)

    翻译 你正在和你的朋友们玩以下这个Nim游戏:桌子上有一堆石头.每次你从中去掉1-3个.谁消除掉最后一个石头即为赢家.你在取出石头的第一轮. 你们中的每个人都有着聪明的头脑和绝佳的策略.写一个函数来确 ...

  9. [LeetCode] 292. Nim Game_Easy tag: Math

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

随机推荐

  1. 等价类划分方法的应用(jsp)

    [问题描述] 在三个文本框中输入字符串,要求均为1到6个英文字符或数字,按submit提交. [划分等价类] 条件1: 字符合法; 条件2: 输入1长度合法; 条件3: 输入2长度合法: 条件4: 输 ...

  2. redis 间断性耗时长问题解决

    我发现开发项目用的redis 隔一两分钟就出现 耗时问题,长达五秒.一开始以为是 redis 服务器不稳定,但运维测试发现redis稳定的,在高并发下最大耗时也就只有100毫秒左右,怎么也不可能达到5 ...

  3. URI编码解码

    .NET string s= System.Web.HttpUtility.UrlEncode("123", System.Text.Encoding.Unicode); //编码 ...

  4. Windows无线网“无法连接到这个网络”的解决办法

    最近我的笔记本(Win10系统)连接无线网时总是出现"无法连接到这个网络"的错误.为此折腾了一天,通过各种百度,终于找到了适合我的解决办法,在此记录一下. 问题描述 最近因为宿舍的 ...

  5. 怎么把Maven项目转为动态Web项目?

  6. C#高级编程笔记2016年10月12日 运算符重载

    1.运算符重载:运算符重重载的关键是在对象上不能总是只调用方法或属性,有时还需要做一些其他工作,例如,对数值进行相加.相乘或逻辑操作等.例如,语句if(a==b).对于类,这个语句在默认状态下会比较引 ...

  7. WPF菜单

    1.Menu Menu 是水平放置它的项的,默认情况下把灰色栏作为背景. 把Menu 添加到它的ItemsControl 基类的唯一公开的API 是IsMainMenu 属性.当为true(默认的)时 ...

  8. 卸载linux Mint自带jdk并安装最新jdk

    查看安装的软件包sudo dpkg --list | grep -i jdk 删除jdksudo apt-get purge openjdk* 删除其他的包sudo apt-get purge ice ...

  9. 使用ROW_NUMBER()+临时表+While 实现表遍历

    declare @table table(dlid int,RowNum int)insert into @table select dlid,ROW_NUMBER() over(order by d ...

  10. 让IE8支持placeholder

    $(function(){ if(!placeholderSupport()){ // 判断浏览器是否支持 placeholder $('[placeholder]').focus(function( ...