Nim games 博弈论
2016-04-19 15:05
99 查看
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 boolean canWinNim(int n) {
if(n%4==0){
return false;
}else{
return true;
}
}
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 boolean canWinNim(int n) {
if(n%4==0){
return false;
}else{
return true;
}
}
相关文章推荐
- Unity3D中使用Profiler精确定位性能热点的优化技巧
- mysql alter 语句用法,添加、修改、删除字段等
- 【C#dynamic 类型】
- leetcode112题 题解 翻译 C语言版 Python版
- maven介绍及常用命令(一)
- Android Unable to resolve target 'android-8'
- Maven生命周期详解
- 启动页
- Swift 下debug状态打印log
- 编写String的构造函数、析构函数、拷贝构造函数、赋值函数
- ThinkPHP 3.1.2 模板中的变量
- iOS_导入libxml2.2框架后,找不到<libxml/tree.h>的解决办法
- [HSON : HC Script Object Notation] Finish Build 1 On GitHub
- php编码解码json对象
- APK瘦身实践
- using的作用
- ThinkPHP 3.1.2 模板中的变量
- ThinkPHP 3.1.2 模板中的变量
- 如何选择适合自己的CMS建站系统
- VirtualBox下Ubuntu利用桥接方式上网