hdu1536(SG函数)

题目

每次给出允许取数的个数,然后给出一堆堆,问是否为必胜态
大概就是一道多case的SG函数题吧

题解

更新F函数,求相应的SG函数,然后每次把所有堆的SG函数值异或求出

代码

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int Maxm=10100,Maxn=105;
int f[Maxn],sg[Maxm],m;
bool Hash[Maxm];
void Getsg()
{
	memset(sg,0,sizeof(sg));
	for(int i=1;i<Maxm;i++){
		//cout<<"i:"<<i<<endl;
		memset(Hash,false,sizeof(Hash));
		for(int j=1;j<=m&&f[j]<=i;j++){
			Hash[sg[i-f[j]]]=true;
			//cout<<sg[i-f[j]]<<' ';
		}
		//cout<<endl;
		for(int j=0;j<=i;j++){
			if(!Hash[j]){
				sg[i]=j;
				//cout<<j<<endl;
				break;
			}
		}
	}
}
int main()
{
	Getsg();
	int m1,m2,m3;
	while(scanf("%d",&m)==1&&m){
		for(int i=1;i<=m;i++){
			scanf("%d",&f[i]);
		}
		sort(f+1,f+m+1);
		int T,ans=0;
		scanf("%d",&T);
		Getsg();
		for(int i=1;i<=T;i++){
			scanf("%d",&m1);
			ans=0;
			for(int j=1;j<=m1;j++){
				scanf("%d",&m2);
				ans=ans^sg[m2];
			}
			if(ans!=0) cout<<'W';
			else cout<<'L';
		}
		cout<<endl;
	}
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值