首页 > 代码库 > BZOJ 1228 E&G(sg函数+找规律)

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

把一对石子堆看出一个子游戏。打出子游戏的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-9
# define MOD 1000000000
# define INF 1000000000
# 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<<1,l,mid
# define rch p<<1|1,mid+1,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=0,f=1;char ch=getchar();
    while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
    while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
    return x*f;
}
void Out(int a) {
    if(a<0) {putchar(-); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+0);
}
const int N=20005;
//Code begin...

int a[N];

int sg(int x, int y){
    LL tmp=2;
    for (int i=0; ; ++i, tmp<<=1) if ((x-1)%tmp<tmp/2 && (y-1)%tmp<tmp/2) return i;
}
int main ()
{
    int T, n;
    scanf("%d",&T);
    while (T--) {
        int ans=0;
        scanf("%d",&n);
        FOR(i,1,n) scanf("%d",a+i);
        FOR(i,1,n/2) ans^=sg(a[2*i-1],a[2*i]);
        puts(ans?"YES":"NO");
    }
    return 0;
}
View Code

 

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