[292]Nim Game
来源:互联网 发布:bcm4306 linux 编辑:程序博客网 时间:2024/06/05 19:02
【题目描述】
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整除的石子块数均必输,反之必赢。
【代码】
class Solution {public: bool canWinNim(int n) { if(n%4==0) return false; else return true; }};
0 0
- Nim Game leetcode 292
- [292]Nim Game
- [LeetCode 292] Nim Game
- leetcode 292---NIM GAME
- leetcode-292-Nim Game
- LeetCode 292----Nim Game
- LeetCode 292 Nim Game
- 292 Nim Game
- 292 Nim Game
- 【LEETCODE】292-Nim Game
- Leetcode #292 Nim Game
- LeetCode 292:Nim Game
- 【LeetCode】292 Nim Game
- LeetCode 292 Nim Game
- Leetcode #292 Nim Game
- [leetcode 292]Nim Game
- 292Nim Game
- Nim Game---292
- Linux 生成 core 文件的方法
- JavaScript高级程序设计之BOM之navigator 对象 第8.3讲笔记
- Unity A*寻路三个简单实用的算法
- Jetty嵌入式web的war的发布方法
- iOS 对Image图片本身进行旋转0,90,180,270
- [292]Nim Game
- 最完整的ftp命令大全
- 用正则表达式验证邮箱和手机号
- 近期工作总结
- 这道Java面试题你真的理解么?好多大神都回答错误!
- ALSA 接口编程实例——语音聊天
- iOS Quartz 绘图
- ScrollView嵌套GridView,并实现GridView竖直分页加载
- IOS网络笔记--base64编码和MD5加密的使用方法