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-02 08:18
集美大学 Java
钱嘛数字而已:没有赛事奖项么?另外,项目经历字有点多哈,建议突出一下重点:用的什么技术,解决什么问题,达到什么效果。
大家都开始春招面试了吗
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务