hrbust 2203 Alice and Bob(规律 博弈)

本文介绍了一款名为A和B的游戏,其中两名玩家Alice和Bob轮流写下整数A和B,使得A²-B²等于给定的整数N。文章分析了游戏策略并提供了判断Alice是否能获胜的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Alice and Bob
Time Limit: 1000 MSMemory 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

SubmitStatisticDiscussSharedcodes

通过题意可以直到最多取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<cstdio>
#include<math.h>
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<stdio.h>
#include<string.h>
#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");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值