ZOJ 月赛 Help Bob

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

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");
    }
} 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值