LeetCode Nim Game (简单nim)
题意:
有一堆石子,里面有n个石头,每次可以从中取出1~3个,两人轮流取,最后一个石子被谁取走即为赢家。你先取,问最后谁赢?
思路:
n%4>0则先手赢,因为每次总是可以给对方留4个石子的倍数,而对方最多只能取到3个,剩下的给先手来取,所以先手赢。
C++:
class Solution {
public:
bool canWinNim(int n) {
return n%>;
}
};
AC代码
python:
class Solution(object):
def canWinNim(self, n):
"""
:type n: int
:rtype: bool
"""
return bool(n&3)
AC代码
LeetCode Nim Game (简单nim)的更多相关文章
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 3032 Nim or not Nim? (sg函数求解)
Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players ...
- Nim or not Nim? hdu3032 SG值打表找规律
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 【HDU3032】Nim or not Nim?(博弈论)
[HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio& ...
- HDU 3032 Nim or not Nim? (sg函数)
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 3032 Nim or not Nim? sg函数 难度:0
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 3032 Nim or not Nim?(博弈,SG打表找规律)
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU3032 Nim or not Nim?(Lasker’s Nim游戏)
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
随机推荐
- hdu1071
#include <iostream> #include <stdio.h> using namespace std; int main() { int t; double x ...
- 没有定义json_encode()函数。
php5是没有json扩展的,需要自行下载. 命令php -m 可以查看安装了哪些扩展. 1.修改php.ini 在php.ini 中加入 extension=json.so:sudo vi /etc ...
- cogs 915. 隐藏口令
915. 隐藏口令 ★★☆ 输入文件:hidden.in 输出文件:hidden.out 简单对比时间限制:1 s 内存限制:128 MB USACO/hidden(译 by Feli ...
- Maven中如何利用继承创建web项目(分层开发)
1.创建父项目parent 新建——Maven Project——勾选Create a Simple Project(skip archetype selected)——填写parent坐标,注意打包 ...
- EasyUI/TopJUI之如何动态改变下拉列表框ComboBox输入框的背景颜色
简单记录一下 前段时间接到客户需求:动态改变下拉列表框ComboBox输入框的背景颜色. 刚开始想的很简单在用户选择列表项的时候,判断一下列表框的value值添加相应的背景颜色就OK了,然而在实际操作 ...
- EIGRP-6-EIGRP数据包
EIGRP在与邻居路由器进行通信时,使用以下7种不同类型的数据包: Hello包 确认包 更新包 查询包 响应包 SIA查询包 SIA响应包 更新包,查询包,响应包,SIA查询包和SIA响应包 ...
- JAVA对象转换JSON
1. 把java 对象列表转换为json对象数组,并转为字符串 复制代码 代码如下: JSONArray array = JSONArray.fromObject(userlist); String ...
- Android的网络通信
Android平台有三种网络接口可以使用,他们分别是:java.net.*(标准Java接口).Org.apache接口和Android.net.*(Android网络接口).大多数的Android应 ...
- unity ForceMode
public float jumpAbility; GetComponent<Rigidbody>().AddForce(Vector3.up * jumpAbility, ForceMo ...
- Murano中的角色
Application Publisher - An individual or company that publishes an application to an application cat ...