{"push_id":1773042827,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"0161808365753638d4ff46f4a04b15cde9973ad2","before":"8d06ca5d0215ca579a08531061d49b9d632eacad","commits":[{"sha":"0161808365753638d4ff46f4a04b15cde9973ad2","author":{"name":"s2117402","email":"c8613d9d983dc480bb27fdf3c645b0cca8ad7378@troy.edu"},"message":"NimGame\n\n题目：\n\nYou are playing the following Nim Game with your friend: There is a\nheap of stones on the table, each time one of you take turns to remove\n1 to 3 stones. The one who removes the last stone will be the winner.\nYou will take the first turn to remove the stones.\n\nBoth of you are very clever and have optimal strategies for the game.\nWrite a function to determine whether you can win the game given the\nnumber of stones in the heap.\n\nFor example, if there are 4 stones in the heap, then you will never win\nthe game: no matter 1, 2, or 3 stones you remove, the last stone will\nalways be removed by your friend.\n\n解答：\n\n博弈论中极为经典的尼姆游戏。有总数为n的石头，每个人可以拿1~m个石头，两个人交替拿，拿到最后一个的人获胜。究竟是先手有利，还是后手有利？\n\n1个石子，先手全部拿走；\n2个石子，先手全部拿走；\n3个石子，先手全部拿走；\n4个石子，后手面对的是先手的第1，2，3情况，后手必胜；\n5个石子，先手拿走1个让后手面对第4种情况，后手必败；\n6个石子，先手拿走2个让后手面对第4种情况，后手必败；\n……\n容易看出来，只有当出现了4的倍数，先手无可奈何，其余情况先手都可以获胜。\n（石子数量为4的倍数）后手的获胜策略十分简单，每次取石子的数量，与上一次先手取石子的数量和为4即可；\n（石子数量不为4的倍数）先手的获胜策略也十分简单，每次都令取之后剩余的石子数量为4的倍数（4*0=0，直接拿光），他就处于后手的位置上，利用上一\n行的策略获胜。","distinct":true,"url":"https://api.github.com/repos/s2117402/leetcode-solution/commits/0161808365753638d4ff46f4a04b15cde9973ad2"}]}
{"actor":{"display_login":"s2117402"}}