日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Nim Game

發(fā)布時間:2025/3/21 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nim Game 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目: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.

?

代碼:

public class Solution {public boolean canWinNim(int n) {return n%4!=0;} }

?

轉(zhuǎn)載于:https://www.cnblogs.com/finalboss1987/p/5079062.html

總結(jié)

以上是生活随笔為你收集整理的Nim Game的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。