[Solution] Chef & Cook Game CodeChef Solution
Problem
There is a non-negative integer array of length . Chef and Cook will play a game on the array with Chef starting first.
In one turn the player will perform the following operation:
- Choose two indices such that and .
- Set and , i.e, subtract from and add to .
The player who is unable to perform the operation loses. If both Chef and Cook play optimally, who will win?
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- The first line of each test case contains a single integer denoting the length of the array.
👇👇👇👇👇
- The second line of teach test case contains integers denoting the initial values of the array.
Output Format
For each test case, output "Chef" if Chef wins, otherwise output "Cook" (without quotes).
Each letter of the output may be printed in either uppercase or lowercase. For example, Chef
, chEf
, CHEF
, and cHEf
will all be treated as equivalent.
Explanation:
For the first test case, Chef wins. Here is the strategy for Chef.
- Initially, .
- In the first turn, Chef will pick and . Then, .
- In the second turn, Cook is can only pick and . Then .
- In the third turn, Chef will pick and . Then .
- In the fourth turn, Cook cannot perform any operation and loses. Therefore, Chef has won.
No comments:
Post a Comment