We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Chessboard Game, Again!
Chessboard Game, Again!
Sort by
recency
|
18 Discussions
|
Please Login in order to post a comment
I'm not really sure if there's something wrong with my code or the way I considered playing the game is different than what's expected. My thought process is that, we are able to use any of the 4 possible moves, and at each move we want to make the most optimal move, rather than just get to the edge and try out best not to cross it. My logic is that we would always try to get to the centre of the board by reducing/increasing x or y while compromising the other one by the least amount possible. Somehow my results just don't match with the expected one. And it's such a long script I don't even know where things might be going wrong.
Can anyone help me below mentioned code showing wrong result for last 3 test case.
import java.io.; import java.math.; import java.security.; import java.text.; import java.util.; import java.util.concurrent.; import java.util.function.; import java.util.regex.; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList;
// class Result {
}
public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int k = sc.nextInt(); int[][] arr = new int[k][2]; for(int i = 0 ; i < k; i++){ arr[i][0] = sc.nextInt(); arr[i][1] = sc.nextInt(); } String result = Result.chessboardGame(arr); System.out.println(result); } } }
Here is Chessboard game again! problem solution in Python Java C++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-chessboard-game-again-problem-solution.html
Too difficult for me
A good one . If You understand grandy theorem of game theory , then it is very easy for you to solve recursively .When our possible moves from a co-ordinate of chess-board has been given .We can compute grandy-value recursively using the help of memoization .
My full solution here https://github.com/joy-mollick/Game-Theory-Problems/blob/master/HackerRank-Chessboard%20Game%2C%20Again!.cpp
Here is the part of my code to compute grandy value of every co-ordinate by given input .