Thursday, December 15, 2016

1253 - Misere Nim

Problem Linkhttp://lightoj.com/volume_showproblem.php?problem=1253

Solution :

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a[103];

    int t,k,ans,ok;

    scanf("%d",&t);

    for(int ca=1;ca<=t;ca++)
    {
        scanf("%d",&k);

        for(int i=1;i<=k;i++)
        {
            scanf("%d",&a[i]);
        }
            ok=0;

           for(int i=1;i<=k;i++)
           {
               if(a[i]==1) ok=1;
               else
               {
                   ok=0;
                   break;
               }
           }
           ans=0;
           for(int i=1;i<=k;i++)
           {
               ans=ans xor a[i];
           }

                if(ok==1 and (k%2!=0)) printf("Case %d: Bob\n",ca);
                else if(ok==1 and (k%2==0)) printf("Case %d: Alice\n",ca);
                else if(ans==0) printf("Case %d: Bob\n",ca);
                else printf("Case %d: Alice\n",ca);
        }

    }


No comments:

Post a Comment