292. Nim Game | 抓石子游戏
来源:互联网 发布:金融数据挖掘工程师 编辑:程序博客网 时间:2024/05/01 03:18
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.
思路:通过分析可以看出n=1,2,3成功,n=4失败,后面的n,如果在n-1,n-2,n-3中的一个数中是失败的,则n是成功的,进一步查看规律则可看出,如果n可以整除4,则n失败,否则成功,那么代码就很简单了.
public boolean canWinNim(int n) {if (n%4==0) {return false;}else return true;}
- 292. Nim Game | 抓石子游戏
- leetcode 292. Nim Game(拿石子游戏)
- POJ 2234 Matches Game NIM曲石子游戏
- HDU 2176 取(m堆)石子游戏(Nim game)
- Nim游戏 Nim Game
- 取石子游戏NIM
- Nim取石子游戏
- [转]NIM取石子游戏
- 类Nim取石子游戏
- 取石子游戏详解NIM
- im Game nim游戏
- Nim Game 博弈游戏
- 【bzoj1115】 石子游戏KAM 阶梯Nim游戏
- LeetCode 292: Nim Game (Nim游戏)
- LeetCode 292 Nim Game(Nim游戏)
- 10165 - Stone Game(Nim游戏)
- [poj2234]Matches Game nim游戏
- HDU2176:取(m堆)石子游戏(Nim)
- 25岁前必读的25本书
- 应用内可随时切换语言时,MJRefresh下拉文字的处理
- as3双击屏幕全屏
- PlayFramework 1 输出所有 WS.url() 访问的 URL
- 关于恢复万象OL的C盘系统后,重装万象OL后MSDE服务不能启动的解决
- 292. Nim Game | 抓石子游戏
- [BZOJ3053]The Closest M Points(kd-tree+堆)
- Linux(Centos)下Java JDK安装
- laravel框架使用git clone时遇到的问题
- 如何在linux系统中用微信开发者工具进行调试
- 2017.2.09【初中部 提高组】模拟赛C组 石子游戏 题解
- grep命令简介+正则表达式+globbing
- 最短路模板
- C++关于继承的那些事