LA 5059 - Playing With Stones

时间:2021-10-24 16:02:09

博弈 SG  由于每个a太大,没有办法递推,但是可以找规律

a为偶数  SG(a)=a/2

a为奇数  SG(a)=SG(a/2)

代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue> #define ll long long
#define lint long long
using namespace std; const int N=4000005;
ll F(ll a)
{
if(a==1)
return 0;
if((a&1)==0)
return (a>>1);
return F(a>>1);
}
int main()
{
//freopen("data.in","r",stdin);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
ll nim=0;
for(int i=1;i<=n;++i)
{
ll a;
cin>>a;
nim=(nim^F(a));
}
if(nim==0)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return 0;
}