Bzoj 1193
Bzoj 1305

Bzoj 1228

coc youyl posted @ 2015年7月02日 16:29 in bzoj , 504 阅读

题目分类:博弈,sg函数,找规律

题意:

将2n堆石子分成n组,每一次可以对某一组元素进行如下操作:

去掉期中一堆并把另一堆分出一部分形成新的一堆。

给出原始状态,问是否有必胜策略。

题解:

每一组元素是相互独立的。

将一组(x,y)作为一个状态。

打出一个范围内的sg函数表找规律。

程序:

#include<cstdio>
using namespace std;
int n,T,x1,x2,ans;
inline int work(long long x,long long y)
{
	for (int i=0;i<=31;i++)
	{
		unsigned long long tp=(1LL<<(i+1));
		if((x-1LL)%tp<tp/2LL&&(y-1LL)%tp<tp/2LL)return i;
	}
}
int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		n/=2;
		ans=0;
		for (int i=1;i<=n;i++)
		{
			scanf("%d %d",&x1,&x2);
			ans^=work(x1,x2);
		}
		if(ans==0)printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter