拿火柴——初探Nim游戏必胜策略

孙熙哲

<p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; &nbsp;今天,我和爸爸妈妈一起玩了一个特别有趣的拿火柴游戏,规则是:在若干有限数量的火柴堆中,两人轮流拿走若干根火柴,不能不拿,谁拿到最后一根谁就赢。我决定挑战一下。</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; &nbsp; 起初,妈妈说一堆火柴太多,我们先来玩3根,我们二人轮流拿,每人每轮只拿1~2根火柴,看谁拿到最后一根谁就赢。我想了一下,立刻抢着说:“妈妈你先拿。”结果不出我所料,我赢了。</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; 接着,妈妈说:“看来你已初步了解这个游戏的奥秘,那我们就增加到12根火柴,规则一样。”这时,我的大脑飞速运转,假设出每人每轮会如何拿、拿几根的各种情况,由于我很想赢,所以我决定先探究出在什么情况下必胜后,再去玩这个游戏。</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; &nbsp;首先,我列出拿取1~10根火柴会遇到的十种情况,分别应该选择先拿还是后拿才能获胜。</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; &nbsp;此时,我在列表中发现了重复出现的周期现象,另外,在留给对方3、6、9时,后拿是必胜点。</h3><p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">根据规律可以总结:必胜策略就是留给对方3的倍数。</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;"><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961);">&nbsp; &nbsp; &nbsp; 这时,一旁的爸爸又抛给我一个问题:如果是17根火柴,你要如何拿才能获胜呢?</span><br></h3><p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">通过列表分析,我发现:17根不是3的倍数。</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">那么必胜策略就是:</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; &nbsp;爸爸点点头说:“那么我们现在火力全开,把规则改一改,谁拿到最后一根火柴谁就输。”</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; &nbsp;我继续研究列表,发现拿到最后一根输,可以转化成拿到倒数第二根则赢。总数减1后,就又适用这个列表了。</h3> <p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; &nbsp;玩这个游戏,我运用到了带余数除法、周期性的认识,归纳递推和转化思想,总结出一套游戏的必胜策略:</h3><p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">①如果火柴总数是3的倍数,后手每次只需要与本回合先手拿的数量凑3根。</h3><p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">②如果火柴总数不是3的倍数,先手第一次拿走数量为“使剩余数量为3的倍数”的火柴数量,后续每回合与后手所拿数量凑3根。</h3><p style="font-family: -webkit-standard; white-space: normal; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto;">&nbsp; &nbsp; &nbsp; &nbsp;通过探究,我发现学好数学不仅可以优化我们的生活,在游戏里也可以变得战无不胜,数学真是太有趣啦!</h3>