forked from sowon-dev/AlgorithmStudy_Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAChessboardGame.java
More file actions
51 lines (44 loc) Β· 1.49 KB
/
AChessboardGame.java
File metadata and controls
51 lines (44 loc) Β· 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package hackerrank;
public class AChessboardGame {
// https://www.hackerrank.com/challenges/a-chessboard-game-1/forum/comments/290655
static String chessboardGame(int t, int x, int y) {
// 체μ€κ²μμ νλ νλ μ΄μ΄ 2λͺ
μ€μ μΉμλ₯Ό 리ν΄νλ λ¬Έμ
// μλ 4κ°μ§ κ·μΉμΌλ‘λ§ μ΄λμ΄ κ°λ₯νκ³ λμ΄μ μ΄λν μ μλ νλ μ΄μ΄κ° μ§κ²λλ€.
// 1. (x-2, y+1)
// 2. (x-2, y-1)
// 3. (x+1, y-2)
// 4. (x-1, y-2)
/* 15X15체μ€νμμ νλ μ΄μ΄1μ΄ μ΄κΈΈ μ μλ μΉΈκ³Ό νλ μ΄μ΄2κ° μ΄κΈΈ μ μλ μΉΈμ μμ±νλ©΄ μλμ κ°λ€.
*
2211 2211 2211 221
2211 2211 2211 221
1111 1111 1111 111
1111 1111 1111 111
2211 2211 2211 221
2211 2211 2211 221
1111 1111 1111 111
1111 1111 1111 111
2211 2211 2211 221
2211 2211 2211 221
1111 1111 1111 111
1111 1111 1111 111
2211 2211 2211 221
2211 2211 2211 221
1111 1111 1111 111
* */
for(int i=0; i<t; i++){
if ((x % 4 == 1 || x % 4 == 2) && (y % 4 == 1 || y % 4 == 2)) {
return "Second";
}
}
return "First";
}
public static void main(String[] args) {
System.out.println(chessboardGame(3,5, 2) + ", ans: Second"); //3 1 3 3
System.out.println(chessboardGame(3,5, 3) + ", ans: First");
System.out.println(chessboardGame(3,8, 8) + ", ans: First");
System.out.println(chessboardGame(3,7, 3) + ", ans: First");
System.out.println(chessboardGame(3,8, 12) + ", ans: First");
System.out.println(chessboardGame(3,9, 7) + ", ans: First");
}
}