1695B - Circle Game - CodeForces Solution


games greedy *1000

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	turn = 0 	if n % 2 == 1:
		print("Mike")
		continue
	else:
		min_a = min(a)
		for i in range(len(a)):
			if a[i] == min_a:
				if i % 2 == 0:
					print("Joe")
					break
				else:
					print("Mike")
					break

C++ Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++)
            cin>>a[i];
        if(n%2!=0)
            cout<<"Mike"<<endl;
        else {
            ll mn_mike=INT_MAX,index_mike,index_joe,mn_joe=INT_MAX;
            for(ll i=0;i<n;i++)
            {
                if(i%2==0 && mn_mike>a[i])
                {
                    //mn_mike=min(mn_mike,a[i]);
                    mn_mike=a[i];
                    index_mike=i;
                }
                if(i%2==1 && mn_joe>a[i]) {
                   // mn_joe=min(mn_joe,a[i]);
                   mn_joe=a[i];
                    index_joe=i;
                }
            }
            if(mn_mike!=mn_joe)
            {
                if(mn_mike>mn_joe)
                    cout<<"Mike"<<endl;
                else cout<<"Joe"<<endl;
            }
            else {
                if(index_mike>index_joe)
                    cout<<"Mike"<<endl;
                else cout<<"Joe"<<endl;
            }

        }
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1725G - Garage
1725B - Basketball Together
735A - Ostap and Grasshopper
1183B - Equalize Prices
1481A - Space Navigation
1437B - Reverse Binary Strings
1362B - Johnny and His Hobbies
1299A - Anu Has a Function
1111A - Superhero Transformation
954A - Diagonal Walking
39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs
755C - PolandBall and Forest
456B - Fedya and Maths
376B - IOU
1623B - Game on Ranges
1118A - Water Buying
1462C - Unique Number
301A - Yaroslav and Sequence
38A - Army
38C - Blinds
1197A - DIY Wooden Ladder
1717D - Madoka and The Corruption Scheme