博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
292. Nim Game
阅读量:4497 次
发布时间:2019-06-08

本文共 836 字,大约阅读时间需要 2 分钟。

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.

 

裸的巴什博弈

java:

1 public class Solution {2     public boolean canWinNim(int n) {3         if (n%4==0)4            return false ;5         else6            return true ;7     }8 }

 

转载于:https://www.cnblogs.com/mengchunchen/p/6001917.html

你可能感兴趣的文章
上传文件
查看>>
typeof
查看>>
@Mapper 和 @MapperScan 区别
查看>>
Unity笔记(3)自学第二天
查看>>
[NOIP2013] 华容道
查看>>
(转)java并发编程--Executor框架
查看>>
算法竞赛入门经典 2.2 循环结构程序设计
查看>>
sql server 2000/2005 判断存储过程、触发器、视图是否存在并删除
查看>>
mysql 隔离级别 脏读 测试
查看>>
Datagridview获取列名为“”的值
查看>>
Python 爬虫的工具列表 附Github代码下载链接
查看>>
IE6/7中li浮动外边距无法撑开ul的解决方法
查看>>
SOS团队介绍
查看>>
python 解析Excel
查看>>
$_SERVER
查看>>
Lambda表达式-使用说明
查看>>
【第一篇:C++与opencv】图片的读取和显示
查看>>
PV inverter启动 ----系列一
查看>>
Windows 8在Vmware 8 中安装提示:windows cannot read the<product key> setting from the unattend answer...
查看>>
牛客训练六:海啸(二维树状数组+vector函数的使用)
查看>>