LeetCode 292:Nim Game
2015-12-11 18:10
309 查看
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.
你正和你的朋友玩Nim Game:桌上有一堆石头,你每次只能取走1~3块石头,而取走最后一块石头的人将获得胜利。在这场游戏中你先行。
你和你的朋友都非常聪明,并且都会选择最优策略来行动。写一个函数来判断在已知石头数目的情况下你能否取得胜利。
例如,如果还剩4块石头时,无论你取走1、2还是3块石头,最后一块石头都将被你朋友取走(从而获得胜利)。
翻译之后补上,就当是练习英语了。
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.
你正和你的朋友玩Nim Game:桌上有一堆石头,你每次只能取走1~3块石头,而取走最后一块石头的人将获得胜利。在这场游戏中你先行。
你和你的朋友都非常聪明,并且都会选择最优策略来行动。写一个函数来判断在已知石头数目的情况下你能否取得胜利。
例如,如果还剩4块石头时,无论你取走1、2还是3块石头,最后一块石头都将被你朋友取走(从而获得胜利)。
class Solution { public: bool canWinNim(int n) { if(n%4==0) return false; return true; } };
翻译之后补上,就当是练习英语了。
相关文章推荐
- struts2中使用原生fileUpload上传文件
- CentOS学习笔记<rz/sz安装>
- angular file upload 队列上传机制
- Xcode7创建的工程发送HTTP请求报错
- 十道海量数据处理面试题
- iOS 3DES加密解密(一行代码搞定)
- Javascript模块化编程(三):require.js的用法
- 蓝桥杯——Anagrams问题 ,字串统计 ,矩阵乘法 ,大小写转换
- IOS 用UIWindow自定义AlertView(最基本代码)
- 和链表有关面试题
- javascript:利用javascript对象的特性去掉数组中的重复项
- 80后、90后应该这样管80后、90后应该这样管
- Android基本常用控件的介绍TextView EditText Button Menu
- Decode Ways
- 【ReviewBoard】安装与配置
- 嵌入式底层软件好书推荐
- Xcode运行设备由iphone/ipad变为my mac的解决方
- Python 一步一步学网络编程
- 解决每次运行Xcode , 都需要输入密码 问题
- iOS: HTTPS 与自签名证书