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

本文共 865 字,大约阅读时间需要 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.

/*1:   赢2:  赢3:  赢4: 不赢5: 赢6: 赢7: 赢8: 不赢*/class Solution {public:    bool canWinNim(int n) {        if (n % 4 == 0){            return false;        }else{            return true;        }    }};

好像很简单的样子。。

 

转载于:https://www.cnblogs.com/simplepaul/p/7955621.html

你可能感兴趣的文章
window.print ()
查看>>
【玩转Ubuntu】01. Ubuntu上配置JDK
查看>>
Leetcode: Path Sum
查看>>
我为什么放弃Go语言
查看>>
pthread_rwlock
查看>>
WEB打印(jsp版)
查看>>
URLEncode与URLDecode总结与实现
查看>>
Gradle 多渠道打包的使用和错误分析(转)
查看>>
压力测试衡量CPU的三个指标:CPU Utilization、Load Average和Context Switch Rate
查看>>
C/C++程序员必须熟练应用的开源项目
查看>>
win32下编译glog
查看>>
C#编程(五十二)----------有序列表
查看>>
攻防工具
查看>>
获取包下的类名
查看>>
Fluent UDF【7】:解释型UDF
查看>>
cocos2dX 之数据存储
查看>>
Android应用程序安装过程浅析
查看>>
浅谈浏览器兼容解决方案
查看>>
react-native 项目实战 -- 新闻客户端(1) -- 初始化项目结构
查看>>
ToggleButton开关状态按钮控件
查看>>