【HDU3032】Nim or not Nim?(博弈论)

【HDU3032】Nim or not Nim?(博弈论)

题面

HDU

题解

\(Multi-SG\)模板题

#include<iostream>
#include<cstdio>
using namespace std;
inline int read()
{
    int x=0;bool t=false;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=true,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return t?-x:x;
}
int SG(int x)
{
    if(x%4==0)return x-1;
    if(x%4==1)return x;
    if(x%4==2)return x;
    if(x%4==3)return x+1;
}
int main()
{
    int T=read();
    while(T--)
    {
        int n=read(),s=0;
        while(n--)s^=SG(read());
        puts(s?"Alice":"Bob");
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/cjyyb/p/9490115.html