Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerEarth Mishki Playing Games problem solution

YASH PAL, 31 July 2024
In this HackerEarth Mishki, Playing Games problem solution Mishki loves playing games, so she asked her friend Hacker to join her in the Game of Stones. In this game, they have N sets of stones, numbered from 1 to N. Each set consists of Ai stones, where 1 <= i <= N.
In each turn, the player can select any of the sets containing at least 1 stone and have to reduce it to half of the present number of stones, i.e Ai/ 2 (Integer Division) from it, and in the case of a single stone, he/she has to empty the set by removing it.
As the game is really interesting, both will play this game on Q days. On each day, they will some select sets of stones numbered from l to r, where 1 <= l <= N and being a lover of the games, every day Mishki will be the first player to take the turn.
The one who won’t be able to play his/her turn in the game (i.e no stones left in the selected set of stones), will lose the game. You need to tell the winner of the game on each day if both the player will play optimally and take their turn alternatively.
HackerEarth Mishki Playing Games problem solution

HackerEarth Mishki Playing Games problem solution.

#include <iostream>
#include <cstdio>
#include <cassert>
#define ll long long
using namespace std;

const int ma = 1e6+6;
int a[ma];
ll prefix_sum[ma];

int check_log(int x)
{
int c=0;
while(x)
{
x>>=1;
c++;
}
return c;
}

int main()
{

int n,q;
scanf("%d%d",&n,&q);

for(int i=0;i<n;i++)
scanf("%d",&a[i]);

prefix_sum[0] = check_log(a[0]);
for(int i=1;i<n;i++)
{
prefix_sum[i] = prefix_sum[i-1]+ check_log(a[i]);
}

int l,r;
for(int i=0;i<q;i++)
{
scanf("%d%d",&l,&r);
l-=1;
r-=1;
if(l==0)
{
if(prefix_sum[r]%2)
printf("Mishkin");
else
printf("Hackern");
}
else
{
ll tp = prefix_sum[r]- prefix_sum[l-1];

if(tp%2)
printf("Mishkin");
else
printf("Hackern");
}
}
return 0;

}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes