292. Nim Game
2016-03-03 00:30
267 查看
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.
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.
public class Solution { public boolean canWinNim(int n) { if(n%4==0) return false; else return true; } }
相关文章推荐
- atitit.MIZIAN 陕北方言 特有词汇 大词典 attilax 整理 h--n v1 q31.xlsx
- atitit.MIZIAN 陕北方言 特有词汇 大词典 attilax 整理 h--n v1 q31.xlsx
- SSH框架总结(框架分析+环境搭建+实例源代码下载)
- javaScript引入方式
- atitit.MIZIAN 陕北方言 特有词汇 大词典 attilax 整理 h--n v1 q31.xlsx
- JQuery源码学习笔记(持续更新中)
- C++设计模式之简单工厂模式
- linux上安装Oracle 11g R2 标准版 64位
- 简单银行管理系统
- 运行程序中出现的小问题
- 数据与数据结构
- Activiti入门教程
- 对初学MFC朋友们的看法意见
- 求数组n中出现次数超过一半的数
- DB2常用命令
- 队列<一>
- 圣思园张龙视频
- zookeeper原理
- Perl eval函数使用实例
- QQ第三方登陆