您的位置:首页 > 其它

hdu3032 Nim or not Nim? SG打表找规律

2014-02-20 04:54 225 查看
      N堆石子,每次两种操作,1:选取一堆,取走若干个;2:选取一堆,将其分成两堆石子。取走最后一个石子的输。

      数据给的很大,一组一组的去求SG函数显然会超=..算一下较小的SG值,发现0--8的SG值分别为0,1,2,4,3,5,6,8,7....发现还是有规律的,那么直接按规律算出SG值最后异或一下答案就出来了..

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int f(int x)
{
int t=x%4;
if (t==0)
{
if (x==0) return 0;
else return x-1;
}
if (t==1 || t==2) return x;
return x+1;
}
int n,m,p,q;
int main()
{
// freopen("in.txt","r",stdin);
int tt;
scanf("%d",&tt);
while (tt--)
{
scanf("%d",&n);
int ans=0;
for (int i=1; i<=n; i++)
{
scanf("%d",&m);
ans=ans^f(m);
}
if (ans) puts("Alice");
else puts("Bob");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: