Leetcode113: Nim Game
2015-10-22 09:48
393 查看
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.
只要数目是4的倍数那么一定输,否则一定赢。
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.
只要数目是4的倍数那么一定输,否则一定赢。
class Solution { public: bool canWinNim(int n) { return n%4==0 ? false:true; } };
相关文章推荐
- seajs学习(4)----require 书写约定
- initWithFrame 和 initWithCoder 区别
- Android Studio如何快速生成get,set,tostring,构造函数 ,添加实现继承方法
- 插入数据
- php curl 报错:SSL certificate problem: unable to get local issuer certificate
- 关于数据的连接以及左(右)链接
- Leetcode-201- Bitwise AND of Numbers Range
- 多线程实例1
- 信息检索评价指标:正确率,召回率和F值
- mysql外键的使用详解
- Win7、Win8无法include stdio.h的解决方法
- 单点登录SSO的实现原理
- 矩阵范数
- 微信支付:回调地址notify_url不能带参数
- Zero Copy初探
- requestScope
- 团队管理心得
- iOS手势识别器
- 提升网站性能开发的10个技巧
- 图像局部特征学习(笔记1之边缘检测)