Hdu2999 sg函数构造

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并重点阐述了AI音视频处理的应用场景和实现方法,如语义识别、语音识别、AR增强现实等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Stone Game, Why are you always there?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 455    Accepted Submission(s): 154


Problem Description
“Alice and Bob are playing stone game...”
“Err.... Feel bored about the stone game? Don’t be so, because stone game changes all the time!”
“What the hell are they thinking for?”
“You know, whenever Alice is trying to make fun of Bob, she asked him to play stone game with him.”
“Poor Bob... What’s the rule today?”
“It seems Alice only allows some fixed numbers of continuous stones can be taken each time. And they begin with one string of stones.”
“A string? Formed as a circle or a line?”
“A line.”
“Well, I think I may help Bob with that.”
“How?”
“I may tell him to skip this round if he has no chance to win.”
“Good idea maybe, I mean, Alice always let Bob play first, because she think herself is smart enough to beat Bob no matter how.”
“Yes, she’s actually right about herself. Let me see if Bob has a chance to win...”
...... 
 

Input
There are multiple test cases, for each test case:
The first line has a positive integer N (1<=N<=100).
The second line contains N positive integers, a1, a2 ... an, separated by spaces, which indicate the fixed numbers Alice gives.
The third line, a positive integer M. (M<=1000)
Following M lines, one positive integer K (K<=1000) each line. K means in this round, the length of the stone string. 
 

Output
For each K, output “1” if Bob has a chance to win, output “2” if Bob has no chance, or “0” if it’s undeterminable.
 

Sample Input
3 1 5 1 1 1
 

Sample Output
1

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
using namespace std;
#define LL __int64
int sg[1010],l,n,m,a[1010],k;
int mex(int x)
{
	if (sg[x]!=-1) return sg[x];
	bool vis[1010];
	memset(vis,0,sizeof(vis));
	for (int i=0;i<l;i++)
		for (int j=0;j<=(x-a[i]);j++)
		{
			if (sg[j]==-1)
				sg[j]=mex(j);
			if (sg[x-j-1]==-1)
				sg[x-j-a[i]]=mex(x-j-a[i]);
			vis[sg[j] ^ sg[x-j-a[i]]]=1;
		}
	for (int i=0;;i++)
	if (!vis[i])
	{
		sg[x]=i;
		break;
	}
	return sg[x];
}
int main()
{
	while (~scanf("%d",&n))
	{
		for (int i=0;i<n;i++)
			scanf("%d",&a[i]);
		sort(a,a+n);
		l=unique(a,a+n)-a;
		scanf("%d",&m);
		memset(sg,-1,sizeof(sg));
		while (m--)
		{
			scanf("%d",&k);
			if (sg[k]==-1)
				sg[k]=mex(k);
			if (sg[k]) puts("1");
			else puts("2");
		}
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值