hrbust 2203 Alice and Bob(规律 博弈)

Alice and Bob
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 19(11 users) Total Accepted: 12(10 users) Rating:  Special Judge: No
Description

Alice and Bob are playing a game called A and B, and the loser will do homework for the winner. The name of the game doesn't come from the initial character of their names. The game is called A and B because they need to write down integer A and integer B in turns and A2 - B2 must be equal to N. N is also an integer given by Jim Zheng. He is the judge of the game. Every time Alice or Bob can write at most 3 sets of A and B, and at least 1 set if there still exist A and B (A2 - B2 = N). The person who cant write A and B in his/her turn will be the loser. In the game, Alice always writes A and B first.

For example, Jim Zheng shows an integer: 5 to Alice and Bob. First, Alice writes 3 sets of A and B: (3, 2), (3, -2), (-3, 2). Then Bob writes 1 set of A and B: (-3, -2). Now, its Alices turn again. But she cant write A and B any more, so she loses.

Now, we can assume Alice and Bob both use the best strategy. Giving you an integer N. Can you tell Alice whether she can win by using the best strategy? Please output yes if Alice can win, or no if she cant.

Input

First line contains an integer T (T >= 1000000), which is the number of cases.

In the next T lines, every line contains an integer N (1 <= N <= 1000000).

Output

Just output one line for each case, output “yes” if Alice can win, or “no” if she can’t.

Sample Input


3
1
2
5


Sample Output

yes
no
no


Source
CPC23 2014-6
Author
Zheng Jintao

Submit Statistic Discuss Sharedcodes

通过题意可以直到最多取3个最少娶一个

四个为一个循环

 if(num[n]%4==0)
            printf("no\n");
        else printf("yes\n");

我是这么理解的 

然后暴力打表出num的值

 for(int i=1;i<=50000;i++)
    {
        for(int j=i-1;j>=0;j--)
        {
            if(i*i-j*j>N)
                break;
            if(j==0)
                num[i*i-j*j]+=2;
            else num[i*i-j*j]+=4;
        }
    }

然后做完以后我突然意识到加的除了4就是2

2的时候只有j是0

既然j是0 i*i得到的就是n

那么说只要N是能被完全开方数这题就可以输出yes

否则输出no

开方代码

#include
#include
int main()
{
    int T;
    while(~scanf("%d",&T))
    {
        while(T--)
        {
            int n;
            scanf("%d",&n);
            if(n==(int)sqrt(n)*(int)sqrt(n))
            {
                printf("yes\n");
            }
            else
            {
                printf("no\n");
            }
        }
    }
}




打表代码


#include
#include
#define N 1000000
using namespace std;
int num[N+5];

int main()
{
    int T;
    for(int i=1;i<=50000;i++)
    {
        for(int j=i-1;j>=0;j--)
        {
            if(i*i-j*j>N)
                break;
            if(j==0)
                num[i*i-j*j]+=2;
            else num[i*i-j*j]+=4;
        }
    }
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        if(num[n]%4==0)
            printf("no\n");
        else printf("yes\n");
    }
}

你可能感兴趣的:(hrbust,规律)