SDOI2009 E&D

题目描述

题解:

2e9的博弈肯定要先打表找规律。

求$SG$函数就不说了,直接上表。

乍一看看到了一堆$0$。

仔细一看发现每个$2*2$的方框中只有左上是$0$,其余是同一个数字。

然后增大间隔打表,发现……

代码:

#include<cstdio>
const int N = 20050;
template<typename T>
inline void read(T&x)
{
    T f = 1,c = 0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
    x = f*c;
}
int T,n;
int cal(int x,int y)
{
    int ret = 0;
    while(!((x&y)&1))
    {
        if(x&1)x++;
        if(y&1)y++;
        x>>=1,y>>=1;
        ret++;
    }
    return ret;
}
int main()
{
    read(T);
    while(T--)
    {
        read(n),n/=2;
        int ans = 0;
        for(int a,b,i=1;i<=n;i++)
        {
            read(a),read(b);
            ans^=cal(a,b);
        }
        puts(ans?"YES":"NO");
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/LiGuanlin1124/p/10306592.html