Leetcode 292. Nim Game

Source: Internet
Author: User

Problem:you is playing the following Nim Game with your friend:there isA heap of stones on the table, each time one of your take turns to remove1To3stones. The one who removes, the last stone would be the winner. You'll take the first turn to remove the stones. Both of you is very clever and has optimal strategies forThe game. Write a function to determine whether you can win the game given the number of stonesinchThe heap. For example,ifThere is4StonesinchThe heap, then you'll never win the game:no matter1,2, or3Stones you remove, the last stone is always being removed by your friend.

This title, known as the wining Strange of the Nim game, is impossible to win if the remaining number is a multiple of 4 in his own office. So it detects if N is a multiple of 4. Background See http://www.cdf.toronto.edu/~ajr/270/probsess/03/strategy.html

class Solution {public:    bool canwinnim (int  n) {        if  40returnfalse;         Else return true ;            }};

Leetcode 292. Nim Game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.