Puppy and Game - PUPPYGM Code Chef Easy Question

Hello Everyone , today we will be discussing Puppy and Game , a Code Chef Easy Question .

Here is the link to the PROBLEM

So the answer is pretty simple the winning and losing depends only on the odd or even of the two stacks .

The only case where Vanka will win is when both the stacks have odd peanuts .
Because if he eats either one of them he will be left with an odd number of peanuts and when he splits it he will give an even and an odd stack to Tuzik .

AND Tuzik will again eat the odd stack and split the even stack into two odd stacks .

Finally Tuzik will be left with two ones and he will lose .

Otherwise in all cases , Tuzik will eat the odd stack and then split the remaining even stack into two odd stacks for Vanka and finally Vanka will be left with two ones and will lose .

Please look at the following code and leave any doubts in the comments section :-

Here is the code :-

#include <iostream>
using namespace std;

int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if(a%2==1 && b%2==1)
        {
            cout<<"Vanka"<<endl;
        }
        else
        {
            cout<<"Tuzik"<<endl;
        }
    }
// your code goes here
return 0;
}

Comments

Popular Posts