当前位置:网站首页>【日常训练--腾讯精选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;
}
}
边栏推荐
- CVE-2021-3156 漏洞复现笔记
- 消息队列:消息积压如何处理?
- Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET
- App clear data source code tracking
- 微信小程序蓝牙连接硬件设备并进行通讯,小程序蓝牙因距离异常断开自动重连,js实现crc校验位
- Flinksql 读写pgsql
- ForkJoin最全详解(从原理设计到使用图解)
- 分布式事务解决方案之TCC
- Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
- Getting started with DES encryption
猜你喜欢

Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface

爬虫练习题(三)
![[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation](/img/f6/cd307c03ea723e1fb6a0011b37d3ef.png)
[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation

Differences and introduction of cluster, distributed and microservice

Lombok插件

4. 对象映射 - Mapping.Mapster

R语言【逻辑控制】【数学运算】

得物客服一站式工作台卡顿优化之路

What is message queuing?

论文阅读【Sensor-Augmented Egocentric-Video Captioning with Dynamic Modal Attention】
随机推荐
爬虫练习题(三)
CVE-2021-3156 漏洞复现笔记
JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
关于服装ERP,你知道多少?
【Shell】清理nohup.out文件
sql优化常用技巧及理解
How Alibaba cloud's DPCA architecture works | popular science diagram
Five core elements of architecture design
Talk about mvcc multi version concurrency controller?
Design, configuration and points for attention of network arbitrary source multicast (ASM) simulation using OPNET
Mysql database learning (8) -- MySQL content supplement
Make web content editable
论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
Life experience of an update statement
Leakage relay llj-100fs
Unity keeps the camera behind and above the player
English grammar_ Noun possessive
Differences and introduction of cluster, distributed and microservice
分布式事务解决方案之2PC
English语法_名词 - 所有格