292. Nim Game - LeetCode
Question
Solution
思路:试着列举一下,就能发现一个n只要不是4的倍数,就能赢。
n 是否能赢
1 true
2 true
3 true
4 false 不论删除几,对方都能一把赢
5 true 删除1,还剩4,对方先手,对方输
6 true 删除2,还剩4,对方先手,对方输
7 true 删除3,还剩4,对方先手,对方输
8 false 不论删除几,都能被对方造成还剩4,已方先手,我们就输
9 true
10 true
Java实现:
public boolean canWinNim(int n) {
return n%4 != 0;
}
292. Nim Game - LeetCode的更多相关文章
- LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers
344. Reverse String /** * @param {string} s * @return {string} */ var reverseString = function(s) { ...
- LN : leetcode 292 Nim Game
lc 292 Nim Game 292 Nim Game You are playing the following Nim Game with your friend: There is a hea ...
- 【Leetcode】292. Nim Game
problem 292. Nim Game solution class Solution { public: bool canWinNim(int n) { ; } }; 来generalize一下 ...
- lintcode 394. Coins in a Line 、leetcode 292. Nim Game 、lintcode 395. Coins in a Line II
变型:如果是最后拿走所有石子那个人输,则f[0] = true 394. Coins in a Line dp[n]表示n个石子,先手的人,是必胜还是必输.拿1个石子,2个石子之后都是必胜,则当前必败 ...
- Java实现 LeetCode 292 Nim游戏
292. Nim 游戏 你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解 ...
- 292. Nim Game
292. Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on ...
- 292. Nim Game(C++)
292. Nim Game(C++) You are playing the following Nim Game with your friend: There is a heap of stone ...
- 292. Nim游戏
292. Nim游戏 class Solution(object): def canWinNim(self, n): """ :type n: int :rtype: b ...
- LeetCode 292. Nim Game (取物游戏)
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
随机推荐
- 16_伯德图_手绘技巧与应用_Bode Plot_Part2
- c、c++中-int型以float或者float型以int输出问题
1.将浮点型以整形的类型输出问题 用VC6.0,会把以整形输出形式的浮点数输出为0: 1 #include"stdio.h" 2 int main() 3 { 4 float x= ...
- 5V转10.5V原理图
- PCB模块化布局系列之时钟电路设计(晶振、晶体)
一.晶体在一个电路系统中, 时钟是必不可少的一部分.如人的心脏的作用,如果电路系统的时钟出错了,系统就会发生紊乱,因此在PCB 中设计,一个好的时钟电路是非常必要的.我们常用的时钟电路有:晶体.晶振. ...
- 【Android开发】【布局】 仿微信UI
Demo地址
- 在IntelliJ IDEA配置Tomcat
1,点击Run---EDit Configurations... 2.点击左侧"+"号,找到Tomcat Server---Local(若是没有找到Tomcat Server 可以 ...
- B03. BootstrapBlazor实战 10分钟编写数据库维护项目
demo演示的是Sqlite驱动,FreeSql支持多种数据库,MySql/SqlServer/PostgreSQL/Oracle/Sqlite/Firebird/达梦/神通/人大金仓/翰高/华为Ga ...
- DRF-认证权限频率
目录 DRF-认证权限频率 认证 登录接口 认证 权限 作用 使用 频率 作用 使用 认证权限频率+五个接口 模型 视图 序列化器 认证权限频率类 配置文件 路由 DRF-认证权限频率 前后端混合开发 ...
- tracert命令简述
1. 路由跟踪在线Tracert工具说明 Tracert(跟踪路由)是路由跟踪实用程序,用于确定 IP 数据报访问目标所采取的路径.Tracert 命令用 IP 生存时间 (TTL) 字段和 ICMP ...
- Vue入坑日记: day - 01
前言 最近做了一些小项目,小组里写前端的确实有点拉胯,于是自己动手写前端,因为大一学过web前端基础,所以对HTML,CSS还有印象,就直接对JS下手了,学了两天把JS大致搞明白了,顺便对JQuery ...
