CKS006 - Editorial

Bheeshma Pitamaha and Little Abhimanyu
Author: artha6391
Tester: anushka_nagar
Editorialist: gaurikhard

DIFFICULTY:

EASY-MEDIUM

PREREQUISITES:

GAME THEORY

PROBLEM:

You are given a game where you must eliminate two sticks and put a stick with the difference of the removed sticks. The winner is decided by divisibility of the last stick by 3.

QUICK EXPLANATION:

For all N \leq 1, the game comes to final two numbers where if both numbers are equal, the difference becomes zero which means player with this move wins. If the numbers are not equal still, the last player gets the chance to make it 1 or -1 accordingly. Thus, the player who makes the last move always wins. Hence, the winner depends on whether the moves are even or odd. For N = 1, player A wins since no one can make a move.

SOLUTIONS:

Setter’s Solution

import java.io.;
import java.util.
;
import java.text.;
import java.math.
;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
int k = 0;
for(int a0 = 0; a0 < T; a0++){
int n = in.nextInt();
if(n==1){
System.out.println(“Chef A”);
}
else if(n%2==0){
System.out.println(“Chef A”);
}
else{
System.out.println(“Chef B”);
}
}
}
}

Tester’s Solution

import java.io.;
import java.util.
;
import java.text.;
import java.math.
;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
int k = 0;
for(int a0 = 0; a0 < T; a0++){
int n = in.nextInt();
if(n==1){
System.out.println(“Chef A”);
}
else if(n%2==0){
System.out.println(“Chef A”);
}
else{
System.out.println(“Chef B”);
}
}
}
}

Editorialist’s Solution

import java.io.;
import java.util.
;
import java.text.;
import java.math.
;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
int k = 0;
for(int a0 = 0; a0 < T; a0++){
int n = in.nextInt();
if(n==1){
System.out.println(“Chef A”);
}
else if(n%2==0){
System.out.println(“Chef A”);
}
else{
System.out.println(“Chef B”);
}
}
}
}