-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj_1331.java
More file actions
75 lines (62 loc) · 1.53 KB
/
boj_1331.java
File metadata and controls
75 lines (62 loc) · 1.53 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package baekjoonA;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author TAEK
* @category 시뮬레이션
*
* @see 백준 1331번: 나이트 투어
* 메모리: 12936 KB <br>
* 시간: 80 ms
* @since 2020-08-16
*
*/
public class boj_1331 {
static int[] dx = {-2,-2,-1,-1,1,1,2,2};
static int[] dy = {-1,1,-2,2,-2,2,-1,1};
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
boolean[][] map = new boolean[6][6];
String input = br.readLine();
int col = input.charAt(0) - 'A';
int row = 5 - (input.charAt(1) - '1');
int startC = col;
int startR = row;
map[row][col] = true;
boolean valid = true;
for(int i=1;i<36;i++) {
input = br.readLine();
int nextCol = input.charAt(0) - 'A';
int nextRow = 5 - (input.charAt(1) - '1');
boolean check = false;
for(int j=0;j<8;j++) {
int nx = row + dx[j];
int ny = col + dy[j];
if(nx == nextRow && ny == nextCol) {
row = nx;
col = ny;
check = true;
break;
}
}
if(!check || map[nextRow][nextCol]) {
valid = false;
break;
}
map[row][col] = true;
if(i==35) {
valid = false;
for(int j=0;j<8;j++) {
int nx = row + dx[j];
int ny = col + dy[j];
if(nx == startR && ny == startC) {
valid = true;
break;
}
}
}
}
System.out.println(valid?"Valid":"Invalid");
}
}