lc 292 Nim Game


292 Nim Game

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.

analysation##

Nim Game from baike

We can easily figure out that if the amount is n times as much as 4, then you will surly lose the game.

solution

bool canWinNim(int n) {
if (n%4 == 0)
return 0;
else
return 1;
}

LN : leetcode 292 Nim Game的更多相关文章

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

  2. Java实现 LeetCode 292 Nim游戏

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

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

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

  4. LeetCode 292. Nim Game

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

  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. Spring Cloud 开门见山

    Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,为开发者提供了在分布式系统(配置管理,服务发现,熔断,路由,微代理,控制总线,一次性toke ...

  2. Linux-wget/tar/ln 函数

    1. 获取软件包,可以使用wget的方式, ubuntu可以使用apt-get source来获取源代码 wget 是一个在网络上进行下载的简单而强大的自由软件,支持HTTP,HTTPS,FTP协议, ...

  3. 【PL/SQL练习】显式游标

    cursor --------需要用户先定义,在select时,可以用于处理多行记录 1.declare  声明一个游标 2.open cursor (隐式游标自动open) 3.fetch curs ...

  4. 数据结构(一)之HelloWord

    最近由于学习上面的需要,要重新的看看数据结构方面的知识!当然,我觉得数据结构也非常的重要,下面是我的学习的一点小小的记录,以备日后的查看! 我的环境: 1:操作系统:windows7 2:编码环境:M ...

  5. Cnetos7下,已经能访问tomcat

    进入/usr/local/apache-tomcat-8.0.24/bin 中 执行:./startup.sh开启tomcat 再执行如下 systemctl stop firewalld.servi ...

  6. CSS3 圆形时钟式网页进度条

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. spring+hibernate--直接修改数据库,再通过hibernate查询数据不变

    这个问题已经很多天了,一直没有时间解决,不过还好是自己的项目,没什么影响. 刚好今天没事,想好好解决一下这个问题. hibernate主要配置如下: <property name="h ...

  8. webstorm & phpstorm破解

    webstorm: http://idea.qinxi1992.cn/ http://idea.goxz.gq http://v2mc.net:1017 http://idea.imsxm.com h ...

  9. Use BEC to do mobile phone forensics

    Belkasoft Evidence Center makes me very impressed that it supports lots of evidence type. I have to ...

  10. 事件委托和this

    JavaScript不仅门槛低,而且是一门有趣.功能强大和非常重要的语言.各行各业的人发现自己最混乱的选择是JavaSscript编程语言.由于有着各种各样的背景,所以不是每个人都对JavaScrip ...