-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAChessboardGame.java
More file actions
51 lines (44 loc) ยท 1.49 KB
/
Copy pathAChessboardGame.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");
}
}