-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSWEA1226.cpp
77 lines (69 loc) · 1.71 KB
/
SWEA1226.cpp
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
//
// Created by 전형진 on 2019-07-12.
//
#include <stdio.h>
#include <queue>
using namespace std;
int dy[] = {1,0,-1,0};
int dx[] = {0,1,0,-1};
int map[17][17];
int visit[17][17];
void bfs(int y, int x){
queue<int> xq;
queue<int> yq;
xq.push(x);
yq.push(y);
visit[y][x] = 1;
while(!xq.empty()){
int y = yq.front();
int x = xq.front();
yq.pop();xq.pop();
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if(nx>=0 && ny >=0 && nx<16 && ny < 16 && visit[ny][nx] != 1){
if(map[ny][nx] == 0) {
xq.push(nx);
yq.push(ny);
visit[ny][nx] = 1;
}
if(map[ny][nx] == 3){
xq.push(nx);
yq.push(ny);
visit[ny][nx] = 1;
}
}
}
}
}
int main(){
for (int k = 0; k <10 ; ++k) {
int num;
scanf("%d",&num);
int sx = 0, sy = 0;
int ex = 0, ey = 0;
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
scanf("%1d", &map[i][j]);
if (map[i][j] == 2) {
sx = j;
sy = i;
}
if (map[i][j] == 3) {
ex = j;
ey = i;
}
}
}
bfs(sy, sx);
if (visit[ey][ex] == 1) {
printf("#%d %d\n",num,1);
} else
printf("#%d %d\n",num,0);
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
visit[i][j] = 0;
}
}
}
}