Friday, June 19, 2020

Stick Game

After winning gold and silver in Indian Computing Olympiad 2014, Arun Gupta and Mani Iyer want to have some fun.

Now they are playing a game on a grid made of n horizontal and m vertical sticks.

An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.In the grid shown below,n = 3 and m = 3. There are n+m= 6 sticks in total. There are nm = 9 intersection points, numbered from 1 to 9.

The rules of the game are very simple. The players move in turns. Arun Gupta won gold, so he makes the first move.

During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point.

A player will lose the game if he cannot make a move (i.e. there are no intersection points remaining on the grid at his move).


Assume that both players play optimally. Who will win the game?


Input Format:

The first line of input contains two space-separated integers,n, and m(1 ?n,m? 100).


Output Format:

Print a single line containing "Arun Gupta" or "Mani Iyer" (without the quotes), depending on the winner of the game.


Sample Input 1:

2 2


Sample Output 1:

Mani Iyer


Sample Input 2:

2 3


Sample Output 2:

Mani Iyer


Sample Input 3:

3 3


Sample Output 3:

Arun Gupta


Solution:

#include<iostream>

using namespace std;


int main()

{

    int n, m, res;

    cin >> n >> m;

    if(n < m)

    {

        res = n;

    }

    else

    {

        res = m;

    }

    if(res % 2 == 0)

    {

        cout << “Mani Iyer”;

    }

    else

    {

        cout << “Arun Gupta”;

    }

    return 0;

}


No comments:

Post a Comment

LeetCode 4 Median of Two Sorted Arrays in JavaScript

LeetCode 4, Median of Two Sorted Arrays , asks us to find the median of two already sorted arrays without actually merging them. The key ...

horizontal ads