HDU - 2018 Multi-University Training Contest 2 - 1004: Game

Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

 

Problem Description

Alice and Bob are playing a game.
The game is played on a set of positive integers from 1 to n.
In one step, the player can choose a positive integer from the set, and erase all of its divisors from the set. If a divisor doesn't exist it will be ignored.
Alice and Bob choose in turn, the one who cannot choose (current set is empty) loses.
Alice goes first, she wanna know whether she can win. Please judge by outputing 'Yes' or 'No'.

 

Input
There might be multiple test cases, no more than 10. You need to read till the end of input.
For each test case, a line containing an integer n. (1≤n≤500)

 

Output
A line for each test case, 'Yes' or 'No'.

 

Sample Input
1

 

Sample Output
Yes

题目大意:A / B两人游戏,A先开始,每次在 1~n 中取一个数 i,消除 i 的因子(包括 1 和它自己本身),谁先消除完谁胜利。输入 n,问 A 可以胜利吗?

解题思路:因为一个状态不是必胜态就是必败态。输入 n,如果除 1 以外的(2~n)对 A 来说,如果是必胜态,那么 A 赢了;如果是必败态,那么 A 先把 1 取了,结果就反败为胜。又因为 A 先取,所以先手必赢。

AC 代码

#include<bits/stdc++.h>
#include<cmath>

#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        puts("Yes");
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/dream_weave/article/details/81204071