sdnuoj1253(nimk博弈)

Problem A. Alice and Bob
Description

Alice have a friend Bob, they like play games very much, They like to play games is to grab the stone, this classic game they play much times, so today they intend to make the classic reproduction, playing an overnight grab stone, they are two people who like innovation, so this time they got a new game is playeda. There are N heap stones here.b. Each time you can select stones that do not exceed M heap for any operation c. They play game in turns and cannot do nothingd. People who cannot move stones are loserse. Alice first

Input

The first line is T(0 < T <= 1000) T is TestCaseNext line is N, M(0 < N, M <= 10000)Next line follow N number P, P is the number of stones in the stone heap(0 < P <= 10000)

Output

Case #TestCase: winnerIf Alice win output Alice, otherwise Bob

Sample Input

1
5 1
1 2 3 4 5

Sample Output

Case #1: Alice
nimk模板题

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int sg[N],XOR[N],xxx,num,maxn;
bool solve(int n,int m)
{
    memset(XOR,0,sizeof(XOR));
    maxn=-1;
    for(int i=1;i<=n;i++)
    {
        xxx=sg[i];
        num=0;
        while(xxx)
        {
            XOR[num]+=xxx&1;
            num++;
            xxx>>=1;
        }
        maxn=maxn>num?maxn:num;
    }
    for(int i=0;i<maxn;i++)
    {
        if(XOR[i]%(m+1))
            return true;
    }
    return false;
}
int main()
{
    int t,n,m,i;
    scanf("%d",&t);
    int cnt=1;
    while(t--)
    {
        memset(sg,0,sizeof(sg));
        scanf("%d%d",&n,&m);
        for(i=1;i<=n;i++)
            scanf("%d",&sg[i]);
        if(solve(n,m))
            cout<<"Case #"<<cnt++<<": "<<"Alice"<<'\n';
        else
            cout<<"Case #"<<cnt++<<": "<<"Bob"<<'\n';
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值