Chocolate Division*
Question
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 . The answer is
Known that, since Alf plays first, we can easily find the pattern, which makes sense in our mind also
If
total_cut
is odd, that means Alf will win. (It is easy to understand)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