UVALive 5059 C - Playing With Stones 博弈论Sg函数

本文介绍了一种基于博弈论的游戏算法实现,通过分析玩家在特定条件下的最优策略选择,探讨了如何判断先手玩家是否拥有必胜策略的问题。具体算法包括输入测试案例,通过位运算确定每堆石头的有效状态,并利用异或操作最终得出结论。

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

C - Playing With Stones
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Download as PDF

You and your friend are playing a game in which you and your friend take turns removing stones from piles. Initially there are N piles with a1, a2, a3,..., aN number of stones. On each turn, a player must remove at least one stone from one pile but no more than half of the number of stones in that pile. The player who cannot make any moves is considered lost. For example, if there are three piles with 5, 1 and 2 stones, then the player can take 1 or 2 stones from first pile, no stone from second pile, and only 1 stone from third pile. Note that the player cannot take any stones from the second pile as 1 is more than half of 1 (the size of that pile). Assume that you and your friend play optimally and you play first, determine whether you have a winning move. You are said to have a winning move if after making that move, you can eventually win no matter what your friend does.

Input

The first line of input contains an integer T(T$ \le$100) denoting the number of testcases. Each testcase begins with an integer N(1$ \le$N$ \le$100) the number of piles. The next line contains N integers a1, a2, a3,..., aN(1$ \le$ai$ \le$2 * 1018) the number of stones in each pile.

Output

For each testcase, print ``YES" (without quote) if you have a winning move, or ``NO" (without quote) if you don‟t have a winning move.

Sample Input

4 
2 
4 4 
3 
1 2 3
3 
2 4 6
3 
1 2 1

Sample Output

NO 
YES 
NO 
YES

int n;
int main()
{
    int t;
    scanf("%d",&t);
    while (t--){
        scanf("%d",&n);
        long long cnt=0;
        while (n--){
            long long x;
            scanf("%lld",&x);
            if (x==1) continue;
            while (x&1) x/=2;
            cnt^=x/2;
        }
        if (cnt>0) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值