Chocolate Division*

Question

There is an ungiven condition in this question, that is Alf will play first.

Solution

Idea

This is a pretty awesome question to test your math thinking a.k.a pattern recognition! The easiest way to solve this question is to use the idea of total_cut, which means how many available cuts for a bar of chocolate have given that it is r×cr\times c. The answer is r×c1r\times c - 1

Known that, since Alf plays first, we can easily find the pattern, which makes sense in our mind also

  1. If total_cut is odd, that means Alf will win. (It is easy to understand)

  2. Otherwise, Beata will win.

Code

https://github.com/mendax1234/Coding-Problems/blob/main/kattis/chocolatedivision/chocolatedivision.c
#include <stdio.h>

int main()
{
  int r, c;
  scanf("%d %d", &r, &c);
  int total_cuts = r * c - 1;
  if (total_cuts % 2 == 0)
  {
    printf("Beata\n");
  }
  else
  {
    printf("Alf\n");
  }
}

Last updated