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

全部评论

相关推荐

03-31 18:02
门头沟学院 Java
白日梦想家_等打包版:不要的哦佛给我
点赞 评论 收藏
分享
03-16 13:56
湖南大学 C++
牛客872108596号:到现在没消息是挂了吗查看图片
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务