Stone Game, Why are you always there? - HDU 2999 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): 612    Accepted Submission(s): 203


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
 

题意:对于一行石子,每次每个人可以取给定数目的连续的石子,不能取的输,问先手胜负。

思路:暴力打出所有数目的sg函数。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int T,t,n,m,tot;
int sg[1010],vis[100010],num[110];
void solve()
{
    int i,j,k,l,r;
    sg[0]=0;
    for(i=1;i<=1000;i++)
    {
        tot++;
        for(k=1;k<=n;k++)
        {
            l=0;r=i-num[k];
            while(r>=0)
            {
                vis[sg[l]^sg[r]]=tot;
                r--;
                l++;
            }
        }
        for(k=0;k<=100000;k++)
           if(vis[k]!=tot)
           {
               sg[i]=k;
               break;
           }
    }
}
int main()
{
    int i,j,k;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
           scanf("%d",&num[i]);
        sort(num+1,num+1+n);
        solve();
        scanf("%d",&m);
        while(m--)
        {
            scanf("%d",&k);
            if(sg[k]==0)
              printf("2\n");
            else
              printf("1\n");
        }
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值