Nim Game
2015-10-16 17:01
211 查看
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.
solution:老题了
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.
solution:老题了
bool canWinNim(int n) { return n % 4 != 0; }
相关文章推荐
- Stream/Bytes[]/Image对象相互转化
- 为git配置kdiff3,生效gitk
- 多表联查 若某一字段相同 且有状态跟时间字段,选取该状态下 时间最近的一条数据
- Spring MVC 教程,快速入门,深入分析――如何给spring3 MVC中的Action做JUnit单元测试
- 我的Json解析实战
- [IPhone]如何使用Leak检查内存泄漏
- 我的Json解析实战
- C#新贵开源压缩库SharpCompress压缩文件效率测试
- Spring MVC 教程,快速入门,深入分析――如何把全局异常记录到日志中
- APPIUM常用笔记
- iOS图片拉伸技巧
- Robot Framework web测试demo
- Spring MVC 教程,快速入门,深入分析――如何实现全局的异常处理
- 20150721输入大小写,输出小大写
- 2001-2015ACL历年最佳论文(Best Paper Award)打包下载
- js原型(一)
- SQL FULL JOIN 关键字 高级编程
- linux增加一个子网地址
- 测试word2013发表博客到CSDN中
- 亿级Web系统搭建:单机到分布式集群