leetcode brush 16 title

j today's topic is LeetCode292 brush title, the title is required: the table there is a pile of stone, every time you and your friends can take 1 to 3, removed the last stone of the victory of people, you just get a judge in a given when the number of stones, can win the game.

analysis:

The title is Game Bash 
* When the stones have a 1-m, no doubt, to win the upper hand
* When the stones when there are m + 1, take the upper hand regardless of a few, FLAC can get clean and losing the upper hand
* when the stones when there are m + 2-2m, can take several upper hand, and the remaining m + 1 Ge, the upper hand to win
* we find that faced with m + 1 a stone man must have failed.
* In this case two people through optimal strategy must be to take away the stones, so that when the other party to take the stones as well as m + 1 Ge
* we consider to general promotion: Let the current number of stones is n = k * (m + 1 ) + r
* r th upper hand will first take, assuming the next of x flip away, the upper hand will take a m + 1-x, flip down so that the game will ultimately fail
* current number of stones is disposed n = k * (m + 1)
* x number of assumptions first hand, FLAC will take the m + 1-x months, so go the upper hand must have failed
when we understand the above analysis, it is good to write the code, as follows:
public class canWinNim_292_simple {
    public static boolean solution(int n){
        int num=n%4;
        if (num==0)return false;
        else return true;
    }
}

 

Guess you like

Origin www.cnblogs.com/cquer-xjtuer-lys/p/11411622.html