BZOJ 1228 E&G(sg函数+找规律)

时间:2022-06-22 08:35:19

把一对石子堆看出一个子游戏。打出子游戏的sg表找规律。。

这个规律我是一定找不出来的。。。

对于i,j,如果
(i-1)%pow(2,k+1) < pow(2,k)
(j-1)%pow(2,k+1) < pow(2,k)
那么最小的k值就是sg值。
 
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... int a[N]; int sg(int x, int y){
LL tmp=;
for (int i=; ; ++i, tmp<<=) if ((x-)%tmp<tmp/ && (y-)%tmp<tmp/) return i;
}
int main ()
{
int T, n;
scanf("%d",&T);
while (T--) {
int ans=;
scanf("%d",&n);
FOR(i,,n) scanf("%d",a+i);
FOR(i,,n/) ans^=sg(a[*i-],a[*i]);
puts(ans?"YES":"NO");
}
return ;
}