-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
56 lines (49 loc) Β· 1.75 KB
/
Main.java
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
52
53
54
55
56
package Implementation.P2615;
import java.io.*;
import java.util.*;
public class Main {
static int[][] map = new int[21][21];
static int[] di = {0, 1, 1, 1};
static int[] dj = {1, 0, 1, -1};
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/Implementation/P2615/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int i = 1; i <= 19; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 1; j <= 19; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
}
}
game();
}
static void game() {
for (int i = 1; i <= 19; i++) {
for (int j = 1; j <= 19; j++) {
if (map[i][j] == 0) continue;
for (int k = 0; k < 4; k++) {
if (isWin(i, j, k, map[i][j])) {
System.out.println(map[i][j]);
if (k == 3) System.out.println((i+4) + " " + (j-4));
else System.out.println(i + " " + j);
return;
}
}
}
}
System.out.println(0);
}
static boolean isWin(int i, int j, int d, int n) {
int cnt = 1;
int to_i = i + di[d], to_j = j + dj[d];
while (isValidPath(to_i, to_j) && map[to_i][to_j] == n) {
cnt ++;
to_i += di[d];
to_j += dj[d];
}
int pr_i = i-di[d], pr_j = j-dj[d];
return cnt == 5 && (!isValidPath(pr_i, pr_j) || map[pr_i][pr_j] != n);
}
static boolean isValidPath(int i, int j) {
return 1 <= i && i <= 19 && 1 <= j && j <= 19;
}
}