题意:

  有一堆石子,里面有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)的更多相关文章

  1. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  3. 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 ...

  4. 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 ...

  5. 【HDU3032】Nim or not Nim?(博弈论)

    [HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio& ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. NVI模式

    简介: --NVI即(Non-VIrtual Interface)模式强化依赖倒置,介于 Virtual与No Virtual 之间 允许子类重新实现 也可以在父类中对子类 进行限制和其它操作. 由来 ...

  2. Vue实现添加、删除、关键字查询

    从今天开始,将不定期更新关于 Vue 的学习以及各种方法的使用,好了,下面就开始吧 Vue的实例创建首先需要我们引入一个vue.js(也可以在本地npm安装vue,我为了省事就...),然后在HTML ...

  3. http://lorempixel.com/ 可以快速产生假图

    http://lorempixel.com/可以快速产生假图

  4. Spark BlockManager 概述

    Application 启动的时候: 1. 会在 SparkEnv 中实例化 BlockManagerMaster 和 MapOutputTracker,其中 (a) BlockManagerMast ...

  5. CF868F Yet Another Minimization Problem(决策单调性)

    题目描述:给定一个序列,要把它分成k个子序列.每个子序列的费用是其中相同元素的对数.求所有子序列的费用之和的最小值. 输入格式:第一行输入n(序列长度)和k(需分子序列段数).下一行有n个数,序列的每 ...

  6. Python之PIP安装

    Python有两个著名的包管理工具easy_install.py和pip.Python2.7的安装包中自带了easy_install.py,而pip需要手动安装.而在Python3.5之后都是默认安装 ...

  7. flush logs时做的操作

    flush logs时做的操作:  对于一般查询日志和慢日志,先关闭文件再打开  对于binlog,关闭当前的,开始用下一个新的  用错误日志文件的话,先关闭再打开flush logs可以对一般查询日 ...

  8. Processes and Application Life Cycle

    进程的生命期 Android系统会尽量维持一个进程的生命,直到最终需要为新的更重要的进程腾出内存空间.为了决定哪个该杀哪个该留,系统会跟据运行于进程内的组件的和组件的状态把进程置于不同的重要性等级.当 ...

  9. Sqoop Import HDFS

    Sqoop import应用场景——密码访问 注:测试用表为本地数据库中的表 1.明码访问 sqoop list-databases \ --connect jdbc:mysql://202.193. ...

  10. 工作经验(JNI篇)

    我的工作是C++开发,主要是做底层的,由于要做跨平台的原因,常会做成JNI给Java调用,下面是工作时总结的经验希望有用 JNI只能使用C语言的方式编译,所以,要使用C++的话,要用 extern & ...