当前位置:网站首页>[daily training -- Tencent selected 50] 292 Nim games
[daily training -- Tencent selected 50] 292 Nim games
2022-07-07 05:49:00 【Puppet__】
subject
You and your friends , Play with two people Nim game :
There is a pile of stones on the table .
You take turns in your rounds , You are the first to .
Every round , It's your turn to take it off 1 - 3 A stone .
The man who takes the last stone is the winner .
Let's assume that every step is the optimal solution . Please write a function , To determine if you can give a given number of stones n Win the game without . If you can win , return true; otherwise , return false .
Example 1:
Input :n = 4
Output :false
explain : Here are the possible results :
- remove 1 A stone . Your friend moved away 3 A stone , Including the last piece . Your friend won .
- remove 2 A stone . Move your friend 2 A stone , Including the last piece . Your friend won .
3. You move 3 Stone . Your friend removed the last stone . Your friend won .
Of all the results , Your friend is the winner .
Example 2:
Input :n = 1
Output :true
Example 3:
Input :n = 2
Output :true
Tips :
1 <= n <= 231 - 1
Code
class Solution {
// simplify nim game
public boolean canWinNim(int n) {
// As long as you always have four left for each other, you can guarantee your victory
return n % 4 != 0;
}
}
边栏推荐
- Sidecar mode
- Three level menu data implementation, nested three-level menu data
- 【日常训练--腾讯精选50】292. Nim 游戏
- High voltage leakage relay bld-20
- Educational Codeforces Round 22 B. The Golden Age
- make makefile cmake qmake都是什么,有什么区别?
- async / await
- bat 批示处理详解
- Common skills and understanding of SQL optimization
- 404 not found service cannot be reached in SAP WebService test
猜你喜欢
OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
如何提高网站权重
What are the common message queues?
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
JVM the truth you need to know
The year of the tiger is coming. Come and make a wish. I heard that the wish will come true
上海字节面试问题及薪资福利
CVE-2021-3156 漏洞复现笔记
Preliminary practice of niuke.com (9)
得物客服一站式工作台卡顿优化之路
随机推荐
[paper reading] semi supervised left atrium segmentation with mutual consistency training
TCC of distributed transaction solutions
分布式全局ID生成方案
Simple case of SSM framework
What is dependency injection (DI)
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
zabbix_get测试数据库失败
Mysql-centos7 install MySQL through yum
[shell] clean up nohup Out file
Message queuing: how to ensure that messages are not lost
Realize GDB remote debugging function between different network segments
Paper reading [open book video captioning with retrieve copy generate network]
Hcip seventh operation
谈fpga和asic的区别
Educational Codeforces Round 22 B. The Golden Age
如何提高网站权重
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
Input of native applet switches between text and password types
What are the common message queues?
5. 数据访问 - EntityFramework集成