首页 > 代码库 > 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

打表找规律即可。

1,1,2,2,2,3,3,3,3,4,4,4,4,4...

注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关。

//#include<cstdio>
//#include<set>
//#include<cstring>
//using namespace std;
//bool vis[16];
//int n,SG[16][1<<16];
//int sg(int x,int moved)
//{
//	if(SG[x][moved]!=-1)
//	  return SG[x][moved];
//	set<int>S;
//	for(int i=1;i<=x;++i)
//	  if(!((moved>>(i-1))&1))
//	    S.insert(sg(x-i,moved|(1<<(i-1))));
//	for(int i=0;;++i)
//	  if(S.find(i)==S.end())
//	    return SG[x][moved]=i;
//}
//int main()
//{
//	scanf("%d",&n);
//	for(int i=1;i<=n;++i)
//	  {
//	  	memset(SG,-1,sizeof(SG));
//	  	printf("%d:%d\n",i,sg(i,0));
//	  }
//	return 0;
//}
#include<cstdio>
using namespace std;
int sg[100],n,ans,e;
int main()
{
//	freopen("e.in","r",stdin);
	int x;
	for(int i=1;;++i)
	  {
	  	for(int j=1;j<=i+1;++j)
	  	  {
	  	  	sg[++e]=i;
	  	  	if(e==60)
	  	  	  goto OUT;
	  	  }
	  }
	OUT:
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	  {
	  	scanf("%d",&x);
	  	ans^=sg[x];
	  }
	puts(ans ? "NO" : "YES");
	return 0;
}

【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones