1. 程式人生 > >zoj 3882 Help Bob(zoj 2015年7月月賽)

zoj 3882 Help Bob(zoj 2015年7月月賽)

std sam sim bsp mea multiple ipa long sans

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

題目大意:

有1到n個數字,兩個人輪流選1個數。並把它的全部約數擦去。擦去最後一個數的人贏,輸出先手必勝還是必敗。

解題思路:

如果後手能贏。也就是說後手有必勝策略,使得先手第一次不管取哪個石子,後手都能獲得最後的勝利。那麽如今如果先手取1,接下來

後手通過某種取法使自己進入必勝狀態,可是,先手第1次取得時候就能夠和後手這次取的一樣,搶先進入必勝局面。於是除了0。其它都是

必勝。

代碼:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n==0)
        printf("fail\n");
        else
        printf("win\n");
    }
    return 0;
}


zoj 3882 Help Bob(zoj 2015年7月月賽)