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. Tomcat下conf下server.xml的文件配置信息

    Tomcat下conf下server.xml的文件配置信息,基本上不用做任何修改就可以使用,修改的地方就是host区域的一些配置,此文件设置端口为80. 注意:Tomcat配置文件中(即server. ...

  2. XML基础

    什么是XML? XML(Extensible Markup Language)可扩展标记语言,是一种以简单文本格式存储数据的方式. 它最重要的组成部分是XML元素,包含了文档的实际数据. XML的几个 ...

  3. icomoon图标的使用

    这里的图标可以自己定义 网址:https://icomoon.io/app/#/select/ 定义完后,自己下载下来 引用:    <link href="css/style.css ...

  4. 关于Access restriction: The type 'Application' is not API (restriction on required library)

    原文链接:http://rxxluowei.iteye.com/blog/671893 今天写第一次写JavaFX的入门程序就GG 遇到了导入API的问题,无奈疯狂地通过网络找解决方案.. 我的问题是 ...

  5. tomcat 快速部署静态文件

    server.conf配置: <?xml version='1.0' encoding='utf-8'?> <!-- Licensed to the Apache Software ...

  6. Android Studio 导出jar包

    不像在Eclipse,可以直接导出jar包.AndroidStudio只可以生成aar包. 在网上看到许多朋友问怎么可以像Eclipse一样导出jar包,其实我们只要知道它的原理就可以了. 用jar命 ...

  7. Qt-导入第三方库

    Qt提供了显式和隐式导入第三方库方法,本文只介绍显示导入方法. 第三方提供的库文件包括ControlCAN.h,ControlCAN.dll和ControlCAN.lib.将ControlCAN.h和 ...

  8. (原创)RecyclerView结合xUtils2.6实现滚动时不加载item,xUtils2.6的源码分析与改造

    我们知道xUtils中的bitmapUtils与listview相配合可以实现滚动时暂停加载 只需要一句话: listview.addOnScrollListener(new PauseOnScrol ...

  9. RIDE小技巧——Content Assistance快捷键(CTRL+空格)的修改

    大家在用RIDE Content Assistance功能的快捷键时会与机器中是输入法的切换相冲突,这里提供一下修改的位置,大家可以根据个人的喜好修改. 有三处需要修改: {Python_home}\ ...

  10. tornado 异步调用系统命令和非阻塞线程池

    项目中异步调用 ping 和 nmap 实现对目标 ip 和所在网关的探测 Subprocess.STREAM 不用担心进程返回数据过大造成的死锁, Subprocess.PIPE 会有这个问题. i ...