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

全部评论

相关推荐

最近和朋友聊天,她说了句让我震惊的话:"我发现我连周末点外卖都开始'最优解'了,一定要赶在高峰期前下单,不然就觉得自己亏了。"这不就是典型的"班味入侵"吗?工作思维已经渗透到生活的方方面面。
小型域名服务器:啊?我一直都这样啊?我还以为是我爱贪小便宜呢?每次去实验室都得接一杯免费的开水回去,出门都得规划一下最短路径,在宿舍就吃南边的食堂,在实验室就吃北边的食堂,快递只有顺路的时候才取。
点赞 评论 收藏
分享
jack_miller:我给我们导员说我不在这里转正,可能没三方签了。导员说没事学校催的时候帮我想办法应付一下
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务