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;
}

全部评论

相关推荐

10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务