NO.6_292. Nim Game
来源:互联网 发布:linux分区最大容量 编辑:程序博客网 时间:2024/06/08 09:29
292. Nim Game
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.
Hint:
- If there are 5 stones in the heap, could you figure out a way to remove the stones such that you will always be the winner?
class Solution {public: bool canWinNim(int n) { bool res; if(n%4==0)return 0; else return 1; }};
0 0
- NO.6_292. Nim Game
- LeetCode--No.292--Nim Game
- No.1 Nim Game 取物游戏
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- Nim Game
- SpringMVC Junit单元测试
- Codeforces-743B-Chloe and the sequence(二进制思维题)
- Windows Debug 时如何设断点
- 外部的js文件 如何用el表达式
- Android Log(一) 自定义带类名与方法名的Log
- NO.6_292. Nim Game
- Qt 打印PDF
- 医疗保险管理系统设计 Java
- Go-Sort(Cont)
- 2016 寒假集训有感
- JS前端验证
- 【排序及算法】冒泡/选择/插入/快速排序、顺序查找/折半查找算法
- 感觉自己在做梦1.14
- ArrayList源码分析