zoukankan      html  css  js  c++  java
  • 292. Nim Game

    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.

    此题比较有趣,举例子就可以看的出来了,只要是4的倍数,就会赢的,代码如下:

    1 public class Solution {
    2     public boolean canWinNim(int n) {
    3         if(n%4==0) return false;
    4         else return true;
    5     }
    6 }
  • 相关阅读:
    Day Six(Beta)
    Day Five (beta)
    Day Four(Beta)
    Day Three(Beta)
    Day Two(Beta)
    Day One(Beta)
    项目冲刺——总结
    beta版本贡献率
    软件工程实践总结
    团队作业--Beta版本冲刺
  • 原文地址:https://www.cnblogs.com/codeskiller/p/6482027.html
Copyright © 2011-2022 走看看