leetcode292 Nim Game
2016-03-05 11:00
225 查看
292. Nim Game
Total Accepted:50767 Total Submissions:
98218 Difficulty: Easy
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.
class Solution { public: bool canWinNim(int n) { return (n%4 == 0) ? 0 : 1; } };
相关文章推荐
- 仿QQ侧滑效果ViewDragHelper
- 关于socket编程中io流的总结
- WinCE系统深度定制汇总
- 位与运算在iOS中的使用
- 根文件系统的构建与分析(三)之根文件目录及最简/dev目录
- Zend Framework动作助手Url用法详解
- iOS开发如何通过UMeng的错误分析解决crash问题
- tomcat下配置https环境
- 分布式技术一周技术动态 2016.03.06
- 需求 - 19 - 按钮图片文字上下居中
- 根文件系统的构建与分析(二)之构建动态库
- [精]Odoo 8.0深入浅出开发教程(五) Odoo开发模块
- CodeIgnitier常用方法总结
- 安卓事件机制与页面跳转
- 青蛙跳台阶
- 分支合并
- HDOJ 1281 棋盘游戏(二分图最大匹配)
- 学习进度条
- Swift - 时间控制器NSTimer(每隔一定时间执行某个函数)
- Odoo 8.0深入浅出开发教程(四) Odoo入门