Nam Game
哪一方最终给对方留下4的倍数个石头则win,即想方设法的给对方留下4的倍数个石头。
例如: 9(B win)
A:3
B:2(B取2,给对方余4,对方则lose)
A:1 | 2 | 3
B:3 | 2 | 1(B win)
例如:9 (A win)
A:1 (留8,4的2倍)
B:1 | 2 | 3 (余下7 | 6 |5)
A:3 | 2 | 1 (余下4,4的1倍)
B:1 | 2 | 3 (余下3 | 2 | 1)
A:3 | 2 | 1 (A win)
当先手一方掌握了可以给对方留下4的倍数的权力,那么这一方就可以稳赢,否则则输
所以python代码实现:
"""
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones. Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap. For example, if there are 4 stones in the heap, then you will never win the game: no matter 1, 2, or 3 stones you remove, the last stone will always be removed by your friend.
"""
class Solution(object):
def canWinNim(self, n):
"""
:type n: int
:rtype: bool
"""
if n % 4 == 0 :
return False
else:
return True
Nam Game的更多相关文章
- NS2 nam中节点及数据流颜色设置
NS2 节点颜色设置在http://hi.baidu.com/jrwen0/item/d105c642f4c3ce36fb89601b说明的比較具体,大家能够參见. 我这里想说的是数据流颜色的设置,相 ...
- Ubuntu 16——安装——ns2.35和nam
Ubuntu 16.04 安装ns2.35+nam 总结出以下安装步骤 1: 更新源 sudo apt-get update #更新源列表 sudo apt-get upgrade #更新已经安装的包 ...
- NS2的LEACH仿真出来的nam文件拓扑的节点为什么x=0,且y=0
查看.tr文件和.nam发文件下所有的节点的x,y值都是(0,0),nam图像更没有运行出来 于是我将if { $opt(sc) == "" } {puts "*** N ...
- 已知有一个Worker 类如下: public class Worker { private int age; private String name; private double salary; public Worker (){} public Worker (String nam
package homework006; public class Worker { private int age; private String name; private double sala ...
- Visual studio 2013 bug:visual studio no editoroptiondefinition export found for the given option nam
昨天VS 2013打开项目,双击cs当文件,下面出现bug. Google没有理由.最后,在刚刚好清理C磁盘缓存用户文件夹. 然后就OK了. 详细的路径是:C:\Users\{当前用户}\AppDat ...
- visual studio no editoroptiondefinition export found for the given option nam
今天用VS 2012打开项目,打开项目时,出现以下的bug.解决方法:清理了在C盘用户文件目录下的缓存. 具体的路径是:C:\Users\{当前用户}\AppData\Local\Microsoft\ ...
- 前端Firebug常见错误:SyntaxError:missing variable nam
出现上面那个问题应该是 某个地方,分号写错了 检查一下是否由于应该写分号的地方写成了其他符号.
- Mysql - 函数
Mysql提供的函数是在是太多了, 很多我都见过, 别说用了. 园子里面, 有人弄了一个比较全的. MYSQL函数 我这里会将他写的完全拷贝下来, 中间会插入一些自己项目中使用过的心得 一.数学函数 ...
- ORACLE中STATUS为INACTIVE但是SERVER为SHARED状态的会话浅析
我们知道当ORACLE数据库启用共享服务器模式时,通过共享服务器模式连接到数据库的会话是有一些特征的.在v$session里面,其SERVER的状态一般为SHARED和NONE, 为SHARED时,表 ...
随机推荐
- yar粗略使用记录
yar是鸟哥(laruence)开发的一个并行的RPC框架.据说sina weibo已经在大规模使用这个框架了.今天初步使用了下,觉得还是挺爽的一个工具. 什么情况适用这个工具呢? 比如一般你有个微博 ...
- cordova添加plugin
cordova添加plugin #在线安装 cordova create chankoujie com.example.chankoujie ChanKouJie cordova plugin add ...
- Vue+Webpack+Grunt集成
说明 Vue.Grunt.Webpack的知识请看官方网站 Grunt Tasks:构建.开发调试.打包,命令:grunt build,grunt default,grunt zipall... We ...
- 开发工程师面试的秘密( 整理自 Export C Programming )
开发工程师面试的秘密 因为打算转战linux平台,所以一直在配置自己喜欢的linux操作系统.同时在看那本<C 专家编程>,这本书主要是针对ANSI C 介绍的,所以和Linux(Unix ...
- 【WP8.1开发】基于应用的联系人存储
上一篇文章所吹的牛是访问系统(手机)上的联系人,当然那只是读不能改,这是自然的,要是让你能随便修改用户的联系人信息的话,那后果很严重,有些恶意开发者就有可能把”你的户口改成猪“. 但是,API也允许应 ...
- maven项目部署打包
方法一.把maven依赖的jar包一起打包 http://maven.apache.org/plugins/maven-assembly-plugin/usage.html pom/build中加入以 ...
- javascript类型系统——数组array
× 目录 [1]创建 [2]本质 [3]稀疏[4]长度[5]遍历[6]类数组 前面的话 除了对象之外,数组Array类型可能是javascript中最常用的类型了.而且,javascript中的数组与 ...
- Android_文件存储
因为项目的需求,想实现一个指导使用的欢迎页效果,通过在网上的询问,给的一种解决办法是通过SharedPreferences文件存储方式来实现,具体的实现类似于通过第一次取得SharedPreferen ...
- c#Dictionary键值对的使用
直接粘代码吧 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- [转]Linux df 命令不更新磁盘数据空间使用情况的解决办法
当你已经找出并remove掉Linux系统中的大容量文件时,然后使用df -h查看使用情况依旧不变时.可尝试如下方法解决 1.找出那个进程占用了哪些已删除的文件 # 查看哪些被文件还在被哪个进程占用 ...