当前位置:网站首页>【日常训练--腾讯精选50】292. Nim 游戏
【日常训练--腾讯精选50】292. Nim 游戏
2022-07-07 00:03:00 【Puppet__】
题目
你和你的朋友,两个人一起玩 Nim 游戏:
桌子上有一堆石头。
你们轮流进行自己的回合, 你作为先手 。
每一回合,轮到的人拿掉 1 - 3 块石头。
拿掉最后一块石头的人就是获胜者。
假设你们每一步都是最优解。请编写一个函数,来判断你是否可以在给定石头数量为 n 的情况下赢得游戏。如果可以赢,返回 true;否则,返回 false 。
示例 1:
输入:n = 4
输出:false
解释:以下是可能的结果:
- 移除1颗石头。你的朋友移走了3块石头,包括最后一块。你的朋友赢了。
- 移除2个石子。你的朋友移走2块石头,包括最后一块。你的朋友赢了。
3.你移走3颗石子。你的朋友移走了最后一块石头。你的朋友赢了。
在所有结果中,你的朋友是赢家。
示例 2:
输入:n = 1
输出:true
示例 3:
输入:n = 2
输出:true
提示:
1 <= n <= 231 - 1
代码
class Solution {
// 简化nim博弈
public boolean canWinNim(int n) {
// 你只要永远剩下四个给对方就能保证自己的胜利
return n % 4 != 0;
}
}
边栏推荐
- How does mapbox switch markup languages?
- Web architecture design process
- 分布式事务解决方案之2PC
- App clear data source code tracking
- Paper reading [open book video captioning with retrieve copy generate network]
- Zero sequence aperture of leakage relay jolx-gs62 Φ one hundred
- 什么是消息队列?
- 论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
- Egr-20uscm ground fault relay
- AI人脸编辑让Lena微笑
猜你喜欢
随机推荐
Digital innovation driven guide
JVM (XX) -- performance monitoring and tuning (I) -- Overview
《2022中国低/无代码市场研究及选型评估报告》发布
Common skills and understanding of SQL optimization
Taobao store release API interface (New), Taobao oauth2.0 store commodity API interface, Taobao commodity release API interface, Taobao commodity launch API interface, a complete set of launch store i
How to get free traffic in pinduoduo new store and what links need to be optimized in order to effectively improve the free traffic in the store
Flinksql 读写pgsql
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
纪念下,我从CSDN搬家到博客园啦!
毕业之后才知道的——知网查重原理以及降重举例
关于服装ERP,你知道多少?
论文阅读【Sensor-Augmented Egocentric-Video Captioning with Dynamic Modal Attention】
5. Data access - entityframework integration
Five core elements of architecture design
【已解决】记一次EasyExcel的报错【读取xls文件时全表读不报错,指定sheet名读取报错】
pytorch_ 01 automatic derivation mechanism
什么是消息队列?
分布式事务解决方案之TCC
Dj-zbs2 leakage relay
sql优化常用技巧及理解








![[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training](/img/d6/e6db0d76e81e49a83a30f8c1832f09.png)
