bzoj千题计划287:bzoj1228: [SDOI2009]E&D

http://www.lydsy.com/JudgeOnline/problem.php?id=1228

 

打SG函数表,找规律:

若n是奇数m是奇数,则SG(n,m)=0

若n是偶数m是偶数,则SG(n,m)=SG(n/2,m/2)+1

若n是偶数m是奇数,则SG(n,m)=SG(n,m+1)

若n是奇数m是偶数,则SG(n,m)=SG(n+1,m)

 

#include<cstdio>
#include<iostream>

using namespace std;

void read(int &x)
{
    x=0; char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
}

int SG(int n,int m)
{
    int ans=0;
    while(1)
    {
        if(n&1 && m&1) return ans;
        else if(n&1) n++;
        else if(m&1) m++;
        else
        {
            ans++;
            n>>=1;
            m>>=1;
        }
    }
}

int main()
{
    int T,t,n,m,ans;
    read(T);
    while(T--)
    {
        read(t); t>>=1;
        ans=0;
        while(t--)
        {
            read(n); read(m);
            ans^=SG(n,m);
        }
        puts( ans ? "YES" : "NO" );
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8578638.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值