|
1 | 1 | package hackerrank; |
2 | 2 |
|
3 | 3 | public class AChessboardGame { |
| 4 | +// https://www.hackerrank.com/challenges/a-chessboard-game-1/forum/comments/290655 |
| 5 | + static String chessboardGame(int t, int x, int y) { |
| 6 | + // 체스게임을 하는 플레이어 2명 중의 승자를 리턴하는 문제 |
| 7 | + // 아래 4가지 규칙으로만 이동이 가능하고 더이상 이동할 수 없는 플레이어가 지게된다. |
| 8 | + // 1. (x-2, y+1) |
| 9 | + // 2. (x-2, y-1) |
| 10 | + // 3. (x+1, y-2) |
| 11 | + // 4. (x-1, y-2) |
| 12 | +/* 15X15체스판에서 플레이어1이 이길 수 있는 칸과 플레이어2가 이길 수 있는 칸을 작성하면 아래와 같다. |
| 13 | +* |
| 14 | +2211 2211 2211 221 |
| 15 | +2211 2211 2211 221 |
| 16 | +1111 1111 1111 111 |
| 17 | +1111 1111 1111 111 |
4 | 18 |
|
5 | | - static String chessboardGame(int x, int y) { |
6 | | - for (int i = 0; i < 2; i++) { |
7 | | - if (((x - 1) / 2) % 2 == 0 && ((y - 1) / 2) % 2 == 0) { |
| 19 | +2211 2211 2211 221 |
| 20 | +2211 2211 2211 221 |
| 21 | +1111 1111 1111 111 |
| 22 | +1111 1111 1111 111 |
| 23 | +
|
| 24 | +2211 2211 2211 221 |
| 25 | +2211 2211 2211 221 |
| 26 | +1111 1111 1111 111 |
| 27 | +1111 1111 1111 111 |
| 28 | +
|
| 29 | +2211 2211 2211 221 |
| 30 | +2211 2211 2211 221 |
| 31 | +1111 1111 1111 111 |
| 32 | +* */ |
| 33 | + |
| 34 | + for(int i=0; i<t; i++){ |
| 35 | + if ((x % 4 == 1 || x % 4 == 2) && (y % 4 == 1 || y % 4 == 2)) { |
8 | 36 | return "Second"; |
9 | 37 | } |
10 | 38 | } |
11 | | - return "First"; |
| 39 | + return "First"; |
12 | 40 | } |
13 | 41 |
|
14 | 42 | public static void main(String[] args) { |
15 | | - System.out.println(chessboardGame(5, 2) + ", ans: Second"); |
16 | | - System.out.println(chessboardGame(5, 3) + ", ans: First"); |
17 | | - System.out.println(chessboardGame(8, 8) + ", ans: First"); |
| 43 | + System.out.println(chessboardGame(3,5, 2) + ", ans: Second"); //3 1 3 3 |
| 44 | + System.out.println(chessboardGame(3,5, 3) + ", ans: First"); |
| 45 | + System.out.println(chessboardGame(3,8, 8) + ", ans: First"); |
| 46 | + System.out.println(chessboardGame(3,7, 3) + ", ans: First"); |
| 47 | + System.out.println(chessboardGame(3,8, 12) + ", ans: First"); |
| 48 | + System.out.println(chessboardGame(3,9, 7) + ", ans: First"); |
18 | 49 | } |
19 | 50 |
|
20 | 51 | } |
0 commit comments