java “数石子”游戏算法
来源:互联网 发布:郑州办公软件培训 编辑:程序博客网 时间:2024/05/21 10:17
题目:
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.
下面是我的算法实现:
public class Solution { public static boolean canWinNim(int n){ if(n<=0){ return false; }else{ int i = n%4; if(i==0) return false; else return true; } }}
0 0
- java “数石子”游戏算法
- 取石子游戏,JAVA实现
- 算法游戏-黑洞数(java实现)
- “数独”游戏-Java-dfs搜索算法
- 取石子游戏(博弈算法)
- 2177博弈问题 取石子游戏 算法
- 算法——博弈论:取石子游戏
- 取石子游戏_hdu_2516(博弈规律).java
- 石子游戏
- 石子游戏
- 石子游戏
- 石子游戏
- 石子游戏
- 小朋友数数字的游戏 java实现算法
- [算法]游戏'数读’的基本解法 JAVA版。
- 数独游戏java版(一)--核心算法
- poj 1738 取石子游戏 区间dpgarsiawachs算法
- [OpenJudge] 2.5基本算法之搜索 取石子游戏分析
- 开始吧
- 链表元素的比较和删除
- 第一篇
- SQLyog_Enterprise的简单使用
- Java集合类总结
- java “数石子”游戏算法
- 稀疏矩阵的转置
- 在创业公司做架构师
- Git分享(—)—工作流程和常用命令
- TCP接收/发送滑动窗口与内核接收/发送缓冲区之间的关系
- leetcode008 String to Integer (atoi)
- java 简单的“add digits”算法
- 完整的省市县三级联动
- 整合百度推送碰到的问题