leetcode 292.Nim Game

3人阅读 评论(0) 收藏 举报
分类:

leetcode 292.Nim Game

题意:给你一堆n个石头,两个人轮流取,每次可以取1,2,3个,最后一个取完的人赢。你是第一个,问你能不能赢。

简单博弈:

石头个数  赢或者输

        1        1

        2        1

        3        1

        4        0

        5        1

        6        1

        7        1

        8        0

很简单就看到规律了。

1,2,3,4可以很明显看出谁赢谁输;

对于5,我要是希望最后一个取到,只要4,3,2其中有0就可以了;4=0;所以是5=1

对于6,我要是希望最后一个取到,只要5,4,3其中有0就可以了;4=0;所以是6=1

对于7,我要是希望最后一个取到,只要6,5,4其中有0就可以了;4=0;所以是7=1

对于8,我要是希望最后一个取到,只要7,6,5其中有0就可以了;没有0;所以是8=1

以此类推。。。

查看评论

LeetCode笔记:292.Nim Game

问题: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl...
  • Cloudox_
  • Cloudox_
  • 2016-03-24 15:25:18
  • 813

[LeetCode]292.Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac...
  • Winter_ann
  • Winter_ann
  • 2016-03-02 20:50:56
  • 129

[leetcode] 292.Nim Game

题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table...
  • u014673347
  • u014673347
  • 2015-10-14 20:51:21
  • 780

【LeetCode】292.Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac...
  • yuanzexi
  • yuanzexi
  • 2015-12-01 11:53:26
  • 217

LeetCode 292.Nim Game 解题报告

LeetCode 292.Nim Game 解题报告
  • camellhf
  • camellhf
  • 2016-09-14 13:27:21
  • 370

LeetCode 292.Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac...
  • u012348655
  • u012348655
  • 2016-02-17 21:45:45
  • 235

【LeetCode】Jump Game 解题报告

【题目】 Given an array of non-negative integers, you are initially positioned at the first index of t...
  • ljiabin
  • ljiabin
  • 2014-12-09 09:59:53
  • 6300

292.Nim Game

题意:你和你的朋友两个人玩儿Nim游戏。桌子上有一堆石头,你们每人每次只能拿1-3个石头,谁最后拿到石头谁赢。你第一个拿石头 写一个算法,来判断你是否有办法能赢得游戏。 例如,如果...
  • liu450016702
  • liu450016702
  • 2017-03-07 16:20:41
  • 73

LeetCode 488 Zuma Game 解题报告

原文链接: http://hankerzheng.com/blog/Leetcode-Zuma-Game-Problem DescriptionLeetCode 488 Zuma Game You ...
  • hanzheng992
  • hanzheng992
  • 2017-01-26 11:10:14
  • 1052

LeetCode_Jump Game&&Jump Game II

Given an array of non-negative integers, you are initially positioned at the first index of the arra...
  • loveRooney
  • loveRooney
  • 2014-08-09 12:46:38
  • 9840
    个人资料
    持之以恒
    等级:
    访问量: 8361
    积分: 585
    排名: 9万+
    最新评论