LeetCode 292. Nim Game
2016-07-10 15:02
459 查看
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.
出这用题目真的可以吗?
class Solution { public: bool canWinNim(int n) { if(n % 4 == 0) return false; return true; } };
相关文章推荐
- 正则表达式详解
- Redis(五):关于过期键(2)过期键的删除
- NYOJ-111 分数加减法
- git 使用部分总结
- Hibernate 笔记4 实现对数据库的增删改查
- 移动的导航栏的实现
- Linux下编译FFmpeg之下载源文件并编译
- CentOS和Liunx是什么关系?CentOS和RHLR是什么关系?
- NYOJ_349 Sorting It All Out 拓扑排序
- linux for 循环
- FZU 2126 消去游戏
- Android中AIDL实现进程通信(附源码下载)
- jmeter-察看结果树-响应数据,中文显示乱码
- Java多线程系列——原子类的实现(CAS算法)
- 易语言代码统计源码
- Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法
- 168. Excel Sheet Column Title
- find-k-pairs-with-smallest-sums
- Redhat 6.2 下 oracle 11g R2的安装详解第1/2页
- Shortest Word Distance