Help Bob
Time Limit: 2 Seconds Memory Limit: 65536 KB
There is a game very popular in ZJU at present, Bob didn’t meant to participate in it. But he decided to join it after discovering a lot of pretty girls playing it.
There are n stones on the ground and they are marked as 1 to n respectively. There will be 2 players in each competition. And the game rules are simple, A and B take turns to move. Each round, one of them can only take 1 number away, and then pick out all the divisors of the choosed number. When anyone who can not take away 1 number any longer, he will fail the whole game.
Input
There are multiple cases. Each case include an integer number n (0 ≤ n ≤ 100).
Output
For each case, A win, output “win”. If not, output”fail”.
Sample Input1
3
4
Sample Output1
win
win
题意:给n个石子,标记为1,2,……,n;双方人选一个存在的石子编号数,去掉该数的全部因数编号石子。问先手是否必胜。
这个题虽然很多人过了,但是却都不知道怎么过的,n = 0时,先手必输,其余情况先手必胜。
这里我严格证明这个答案的正确性:
先枚举找规律:
n = 0 : 为{}, sg = 0;
n = 1 : 可选1,得{},其 sg = 1;
n = 2:可选1,得{2},sg = 1;
可选2,得{},sg = 0;故最终sg = 1;
n = 3: 可选1,得{2, 3}
可选2,得{3};
可选3,得{2};
而对{2,3},可选2,得{3};也可选3, 得{2}。
这里,留意{2, 3} 推出的两个子集恰与n = 3推出的剩余两个集合相同。若要sg[n = 3] = 1, 则必须有其推出的一个集合sg值为0,而由{2,3}的sg值由{2}、{3}确定,若{2}、{3}的sg值为1,则{2,3}的sg值为0,则可得sg[n=3] = 1;而若{2}、{3}中有一个sg值为0, 则也可得sg[n = 3] = 1. 故sg[n = 3] = 1;
……
你将发现,这不仅对于n=3时,sg = 1比成立,n > 3时,sg = 1同样成立。
O(∩_∩)O~ 可能没讲得太清楚,大家可以留言给我交流。
#include <stdio.h>
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
if (n == 0) printf("win\n");
else printf("fail\n");
}
}

探讨了在特定游戏规则下,如何通过选择石子编号数及其因数,实现先手必胜的目标。通过数学归纳法证明了n=0时先手必输,其余情况下先手必胜的结论。

被折叠的 条评论
为什么被折叠?



