-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2016_nent_1.java
More file actions
88 lines (77 loc) · 1.46 KB
/
2016_nent_1.java
File metadata and controls
88 lines (77 loc) · 1.46 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
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.Scanner;
class Main {
static int[][] map = new int[8][8];
static int[][] visit = new int[8][8];
static boolean[] checks;
static int cnt=0;
public static void DFS(int row, int col) {
visit[row][col] = 1;
if(visit[7][7] == 1) {
checks[cnt] = true;
return ;
}
switch(map[row][col]) {
case 1:
if(col+1 < 8) {
if(map[row][col+1] != 0 && visit[row][col+1] == 0) {
DFS(row, col+1);
}
}
break;
case 2:
if(row+1 < 8) {
if(map[row+1][col] != 0 && visit[row+1][col] == 0) {
DFS(row+1, col);
}
}
break;
case 3:
if(col+1 < 8) {
if(map[row][col+1] != 0 && visit[row][col+1] == 0) {
DFS(row, col+1);
}
}
break;
case 4:
if(row+1 < 8) {
if(map[row+1][col] != 0 && visit[row+1][col] == 0) {
DFS(row+1, col);
}
}
break;
}
}
public static void main(String[] args) {
int n;
int temp;
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
temp = n;
checks = new boolean[n];
for(int i=0; i<n; i++) {
checks[i] = false;
}
while(temp!=0) {
for(int i=0; i<8; i++) {
for(int j=0; j<8; j++) {
visit[i][j] = 0;
}
}
for(int i=0; i<8; i++) {
for(int j=0; j<8; j++) {
map[i][j] = scan.nextInt();
}
}
DFS(0,0);
cnt++;
temp--;
}
for(int i=0; i<n; i++) {
if(checks[i]) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}