Skip to content

Commit 84269fc

Browse files
committedAug 5, 2020
Update
1 parent afe740e commit 84269fc

File tree

9 files changed

+662
-0
lines changed

9 files changed

+662
-0
lines changed
 

‎12/7.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

‎13/1.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
// 도시의 개수, 도로의 개수, 거리 정보, 출발 도시 번호
6+
int n, m, k, x;
7+
vector<int> graph[300001];
8+
// 모든 도시에 대한 최단 거리 초기화
9+
vector<int> d(300001, -1);
10+
11+
int main(void) {
12+
cin >> n >> m >> k >> x;
13+
14+
// 모든 도로 정보 입력 받기
15+
for (int i = 0; i < m; i++) {
16+
int a, b;
17+
cin >> a >> b;
18+
graph[a].push_back(b);
19+
}
20+
21+
// 출발 도시까지의 거리는 0으로 설정
22+
d[x] = 0;
23+
24+
// 너비 우선 탐색(BFS) 수행
25+
queue<int> q;
26+
q.push(x);
27+
while (!q.empty()) {
28+
int now = q.front();
29+
q.pop();
30+
// 현재 도시에서 이동할 수 있는 모든 도시를 확인
31+
for (int i = 0; i < graph[now].size(); i++) {
32+
int nextNode = graph[now][i];
33+
// 아직 방문하지 않은 도시라면
34+
if (d[nextNode] == -1) {
35+
// 최단 거리 갱신
36+
d[nextNode] = d[now] + 1;
37+
q.push(nextNode);
38+
}
39+
}
40+
}
41+
42+
// 최단 거리가 K인 모든 도시의 번호를 오름차순으로 출력
43+
bool check = false;
44+
for (int i = 1; i <= n; i++) {
45+
if (d[i] == k) {
46+
cout << i << '\n';
47+
check = true;
48+
}
49+
}
50+
51+
// 만약 최단 거리가 K인 도시가 없다면, -1 출력
52+
if (!check) cout << -1 << '\n';
53+
}

‎13/2.cpp

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int n, m;
6+
int arr[8][8]; // 초기 맵 배열
7+
int temp[8][8]; // 벽을 설치한 뒤의 맵 배열
8+
9+
// 4가지 이동 방향에 대한 배열
10+
int dx[] = {-1, 0, 1, 0};
11+
int dy[] = {0, 1, 0, -1};
12+
13+
int result;
14+
15+
// 깊이 우선 탐색(DFS)을 이용해 각 바이러스가 사방으로 퍼지도록 하기
16+
void virus(int x, int y) {
17+
for (int i = 0; i < 4; i++) {
18+
int nx = x + dx[i];
19+
int ny = y + dy[i];
20+
// 상, 하, 좌, 우 중에서 바이러스가 퍼질 수 있는 경우
21+
if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
22+
if (temp[nx][ny] == 0) {
23+
// 해당 위치에 바이러스 배치하고, 다시 재귀적으로 수행
24+
temp[nx][ny] = 2;
25+
virus(nx, ny);
26+
}
27+
}
28+
}
29+
}
30+
31+
// 현재 맵에서 안전 영역의 크기 계산하는 메서드
32+
int getScore() {
33+
int score = 0;
34+
for (int i = 0; i < n; i++) {
35+
for (int j = 0; j < m; j++) {
36+
if (temp[i][j] == 0) {
37+
score += 1;
38+
}
39+
}
40+
}
41+
return score;
42+
}
43+
44+
// 깊이 우선 탐색(DFS)을 이용해 울타리를 설치하면서, 매 번 안전 영역의 크기 계산
45+
void dfs(int count) {
46+
// 울타리가 3개 설치된 경우
47+
if (count == 3) {
48+
for (int i = 0; i < n; i++) {
49+
for (int j = 0; j < m; j++) {
50+
temp[i][j] = arr[i][j];
51+
}
52+
}
53+
// 각 바이러스의 위치에서 전파 진행
54+
for (int i = 0; i < n; i++) {
55+
for (int j = 0; j < m; j++) {
56+
if (temp[i][j] == 2) {
57+
virus(i, j);
58+
}
59+
}
60+
}
61+
// 안전 영역의 최대값 계산
62+
result = max(result, getScore());
63+
return;
64+
}
65+
// 빈 공간에 울타리를 설치
66+
for (int i = 0; i < n; i++) {
67+
for (int j = 0; j < m; j++) {
68+
if (arr[i][j] == 0) {
69+
arr[i][j] = 1;
70+
count += 1;
71+
dfs(count);
72+
arr[i][j] = 0;
73+
count -= 1;
74+
}
75+
}
76+
}
77+
}
78+
79+
int main(void) {
80+
cin >> n >> m;
81+
82+
for (int i = 0; i < n; i++) {
83+
for (int j = 0; j < m; j++) {
84+
cin >> arr[i][j];
85+
}
86+
}
87+
88+
dfs(0);
89+
cout << result << '\n';
90+
}

‎13/3.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
class Virus {
6+
public:
7+
int index;
8+
int second;
9+
int x;
10+
int y;
11+
Virus(int index, int second, int x, int y) {
12+
this->index = index;
13+
this->second = second;
14+
this->x = x;
15+
this->y = y;
16+
}
17+
// 정렬 기준은 '번호가 낮은 순서'
18+
bool operator <(Virus &other) {
19+
return this->index < other.index;
20+
}
21+
};
22+
23+
int n, k;
24+
// 전체 보드 정보를 담는 배열
25+
int graph[200][200];
26+
// 바이러스에 대한 정보를 담는 리스트
27+
vector<Virus> viruses;
28+
29+
// 바이러스가 퍼져나갈 수 있는 4가지의 위치
30+
int dx[] = {-1, 0, 1, 0};
31+
int dy[] = {0, 1, 0, -1};
32+
33+
int main(void) {
34+
cin >> n >> k;
35+
36+
// 보드 정보를 한 줄 단위로 입력
37+
for (int i = 0; i < n; i++) {
38+
for (int j = 0; j < n; j++) {
39+
cin >> graph[i][j];
40+
// 해당 위치에 바이러스가 존재하는 경우
41+
if (graph[i][j] != 0) {
42+
// (바이러스 종류, 시간, 위치 X, 위치 Y) 삽입
43+
viruses.push_back(Virus(graph[i][j], 0, i, j));
44+
}
45+
}
46+
}
47+
48+
// 정렬 이후에 큐로 옮기기 (낮은 번호의 바이러스가 먼저 증식하므로)
49+
sort(viruses.begin(), viruses.end());
50+
queue<Virus> q;
51+
for (int i = 0; i < viruses.size(); i++) {
52+
q.push(viruses[i]);
53+
}
54+
55+
int target_s, target_x, target_y;
56+
cin >> target_s >> target_x >> target_y;
57+
58+
// 너비 우선 탐색(BFS) 진행
59+
while (!q.empty()) {
60+
Virus virus = q.front();
61+
q.pop();
62+
// 정확히 second만큼 초가 지나거나, 큐가 빌 때까지 반복
63+
if (virus.second == target_s) break;
64+
// 현재 노드에서 주변 4가지 위치를 각각 확인
65+
for (int i = 0; i < 4; i++) {
66+
int nx = virus.x + dx[i];
67+
int ny = virus.y + dy[i];
68+
// 해당 위치로 이동할 수 있는 경우
69+
if (0 <= nx && nx < n && 0 <= ny && ny < n) {
70+
// 아직 방문하지 않은 위치라면, 그 위치에 바이러스 넣기
71+
if (graph[nx][ny] == 0) {
72+
graph[nx][ny] = virus.index;
73+
q.push(Virus(virus.index, virus.second + 1, nx, ny));
74+
}
75+
}
76+
}
77+
}
78+
79+
cout << graph[target_x - 1][target_y - 1] << '\n';
80+
}

‎13/4.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
// "균형잡힌 괄호 문자열"의 인덱스 반환
6+
int balancedIndex(string p) {
7+
int count = 0; // 왼쪽 괄호의 개수
8+
for (int i = 0; i < p.size(); i++) {
9+
if (p[i] == '(') count += 1;
10+
else count -= 1;
11+
if (count == 0) return i;
12+
}
13+
return -1;
14+
}
15+
16+
// "올바른 괄호 문자열"인지 판단
17+
bool checkProper(string p) {
18+
int count = 0; // 왼쪽 괄호의 개수
19+
for (int i = 0; i < p.size(); i++) {
20+
if (p[i] == '(') count += 1;
21+
else {
22+
if (count == 0) { // 쌍이 맞지 않는 경우에 false 반환
23+
return false;
24+
}
25+
count -= 1;
26+
}
27+
}
28+
return true; // 쌍이 맞는 경우에 true 반환
29+
}
30+
31+
string solution(string p) {
32+
string answer = "";
33+
if (p == "") return answer;
34+
int index = balancedIndex(p);
35+
string u = p.substr(0, index + 1);
36+
string v = p.substr(index + 1);
37+
// "올바른 괄호 문자열"이면, v에 대해 함수를 수행한 결과를 붙여 반환
38+
if (checkProper(u)) {
39+
answer = u + solution(v);
40+
}
41+
// "올바른 괄호 문자열"이 아니라면 아래의 과정을 수행
42+
else {
43+
answer = "(";
44+
answer += solution(v);
45+
answer += ")";
46+
u = u.substr(1, u.size() - 2); // 첫 번째와 마지막 문자를 제거
47+
for (int i = 0; i < u.size(); i++) {
48+
if (u[i] == '(') u[i] = ')';
49+
else u[i] = '(';
50+
}
51+
answer += u;
52+
}
53+
return answer;
54+
}

‎13/5.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int n;
6+
// 연산을 수행하고자 하는 수 리스트
7+
vector<int> arr;
8+
// 더하기, 빼기, 곱하기, 나누기 연산자 개수
9+
int add, sub, mul, divi;
10+
11+
// 최솟값과 최댓값 초기화
12+
int minValue = 1e9;
13+
int maxValue = -1e9;
14+
15+
// 깊이 우선 탐색 (DFS) 메서드
16+
void dfs(int i, int now) {
17+
// 모든 연산자를 다 사용한 경우, 최솟값과 최댓값 업데이트
18+
if (i == n) {
19+
minValue = min(minValue, now);
20+
maxValue = max(maxValue, now);
21+
}
22+
else {
23+
// 각 연산자에 대하여 재귀적으로 수행
24+
if (add > 0) {
25+
add -= 1;
26+
dfs(i + 1, now + arr[i]);
27+
add += 1;
28+
}
29+
if (sub > 0) {
30+
sub -= 1;
31+
dfs(i + 1, now - arr[i]);
32+
sub += 1;
33+
}
34+
if (mul > 0) {
35+
mul -= 1;
36+
dfs(i + 1, now * arr[i]);
37+
mul += 1;
38+
}
39+
if (divi > 0) {
40+
divi -= 1;
41+
dfs(i + 1, now / arr[i]);
42+
divi += 1;
43+
}
44+
}
45+
}
46+
47+
int main(void) {
48+
cin >> n;
49+
for (int i = 0; i < n; i++) {
50+
int x;
51+
cin >> x;
52+
arr.push_back(x);
53+
}
54+
cin >> add >> sub >> mul >> divi;
55+
56+
// DFS 메서드 호출
57+
dfs(1, arr[0]);
58+
59+
// 최댓값과 최솟값 차례대로 출력
60+
cout << maxValue << '\n' << minValue << '\n';
61+
}

‎13/6.cpp

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int n; // 복도의 크기
6+
char board[6][6]; // 복도 정보 (N x N)
7+
vector<pair<int, int> > teachers; // 모든 선생님 위치 정보
8+
vector<pair<int, int> > spaces; // 모든 빈 공간 위치 정보
9+
10+
// 특정 방향으로 감시를 진행 (학생 발견: true, 학생 미발견: false)
11+
bool watch(int x, int y, int direction) {
12+
// 왼쪽 방향으로 감시
13+
if (direction == 0) {
14+
while (y >= 0) {
15+
if (board[x][y] == 'S') { // 학생이 있는 경우
16+
return true;
17+
}
18+
if (board[x][y] == 'O') { // 장애물이 있는 경우
19+
return false;
20+
}
21+
y -= 1;
22+
}
23+
}
24+
// 오른쪽 방향으로 감시
25+
if (direction == 1) {
26+
while (y < n) {
27+
if (board[x][y] == 'S') { // 학생이 있는 경우
28+
return true;
29+
}
30+
if (board[x][y] == 'O') { // 장애물이 있는 경우
31+
return false;
32+
}
33+
y += 1;
34+
}
35+
}
36+
// 위쪽 방향으로 감시
37+
if (direction == 2) {
38+
while (x >= 0) {
39+
if (board[x][y] == 'S') { // 학생이 있는 경우
40+
return true;
41+
}
42+
if (board[x][y] == 'O') { // 장애물이 있는 경우
43+
return false;
44+
}
45+
x -= 1;
46+
}
47+
}
48+
// 아래쪽 방향으로 감시
49+
if (direction == 3) {
50+
while (x < n) {
51+
if (board[x][y] == 'S') { // 학생이 있는 경우
52+
return true;
53+
}
54+
if (board[x][y] == 'O') { // 장애물이 있는 경우
55+
return false;
56+
}
57+
x += 1;
58+
}
59+
}
60+
return false;
61+
}
62+
63+
// 장애물 설치 이후에, 한 명이라도 학생이 감지되는지 검사
64+
bool process() {
65+
// 모든 선생의 위치를 하나씩 확인
66+
for (int i = 0; i < teachers.size(); i++) {
67+
int x = teachers[i].first;
68+
int y = teachers[i].second;
69+
// 4가지 방향으로 학생을 감지할 수 있는지 확인
70+
for (int i = 0; i < 4; i++) {
71+
if (watch(x, y, i)) {
72+
return true;
73+
}
74+
}
75+
}
76+
return false;
77+
}
78+
79+
bool found; // 학생이 한 명도 감지되지 않도록 설치할 수 있는지의 여부
80+
81+
int main(void) {
82+
cin >> n;
83+
84+
for (int i = 0; i < n; i++) {
85+
for (int j = 0; j < n; j++) {
86+
cin >> board[i][j];
87+
// 선생님이 존재하는 위치 저장
88+
if (board[i][j] == 'T') {
89+
teachers.push_back({i, j});
90+
}
91+
// 장애물을 설치할 수 있는 (빈 공간) 위치 저장
92+
if (board[i][j] == 'X') {
93+
spaces.push_back({i, j});
94+
}
95+
}
96+
}
97+
98+
// 빈 공간에서 3개를 뽑는 모든 조합을 확인
99+
vector<bool> binary(spaces.size());
100+
fill(binary.end() - 3, binary.end(), true);
101+
do {
102+
// 장애물들을 설치해보기
103+
for (int i = 0; i < spaces.size(); i++) {
104+
if (binary[i]) {
105+
int x = spaces[i].first;
106+
int y = spaces[i].second;
107+
board[x][y] = 'O';
108+
}
109+
}
110+
// 학생이 한 명도 감지되지 않는 경우
111+
if (!process()) {
112+
// 원하는 경우를 발견한 것임
113+
found = true;
114+
break;
115+
}
116+
// 설치된 장애물을 다시 없애기
117+
for (int i = 0; i < spaces.size(); i++) {
118+
if (binary[i]) {
119+
int x = spaces[i].first;
120+
int y = spaces[i].second;
121+
board[x][y] = 'X';
122+
}
123+
}
124+
} while(next_permutation(binary.begin(), binary.end()));
125+
126+
if (found) cout << "YES" << '\n';
127+
else cout << "NO" << '\n';
128+
}

‎13/7.cpp

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
// 땅의 크기(N), L, R 값을 입력받기
6+
int n, l, r;
7+
8+
// 전체 나라의 정보(N x N)를 입력받기
9+
int graph[50][50];
10+
int unions[50][50];
11+
12+
int dx[] = {-1, 0, 1, 0};
13+
int dy[] = {0, -1, 0, 1};
14+
15+
// 특정 위치에서 출발하여 모든 연합을 체크한 뒤에 데이터 갱신
16+
void process(int x, int y, int index) {
17+
// (x, y)의 위치와 연결된 나라(연합) 정보를 담는 리스트
18+
vector<pair<int, int> > united;
19+
united.push_back({x, y});
20+
// 너비 우선 탐색 (BFS)을 위한 큐 라이브러리 사용
21+
queue<pair<int, int> > q;
22+
q.push({x, y});
23+
unions[x][y] = index; // 현재 연합의 번호 할당
24+
int summary = graph[x][y]; // 현재 연합의 전체 인구 수
25+
int count = 1; // 현재 연합의 국가 수
26+
// 큐가 빌 때까지 반복(BFS)
27+
while (!q.empty()) {
28+
int x = q.front().first;
29+
int y = q.front().second;
30+
q.pop();
31+
// 현재 위치에서 4가지 방향을 확인하며
32+
for (int i = 0; i < 4; i++) {
33+
int nx = x + dx[i];
34+
int ny = y + dy[i];
35+
// 바로 옆에 있는 나라를 확인하여
36+
if (0 <= nx && nx < n && 0 <= ny && ny < n && unions[nx][ny] == -1) {
37+
// 옆에 있는 나라와 인구 차이가 L명 이상, R명 이하라면
38+
int gap = abs(graph[nx][ny] - graph[x][y]);
39+
if (l <= gap && gap <= r) {
40+
q.push({nx, ny});
41+
// 연합에 추가하기
42+
unions[nx][ny] = index;
43+
summary += graph[nx][ny];
44+
count += 1;
45+
united.push_back({nx, ny});
46+
}
47+
}
48+
}
49+
}
50+
// 연합 국가끼리 인구를 분배
51+
for (int i = 0; i < united.size(); i++) {
52+
int x = united[i].first;
53+
int y = united[i].second;
54+
graph[x][y] = summary / count;
55+
}
56+
}
57+
58+
int totalCount = 0;
59+
60+
int main(void) {
61+
cin >> n >> l >> r;
62+
63+
for (int i = 0; i < n; i++) {
64+
for (int j = 0; j < n; j++) {
65+
cin >> graph[i][j];
66+
}
67+
}
68+
69+
// 더 이상 인구 이동을 할 수 없을 때까지 반복
70+
while (true) {
71+
for (int i = 0; i < n; i++) {
72+
for (int j = 0; j < n; j++) {
73+
unions[i][j] = -1;
74+
}
75+
}
76+
int index = 0;
77+
for (int i = 0; i < n; i++) {
78+
for (int j = 0; j < n; j++) {
79+
if (unions[i][j] == -1) { // 해당 나라가 아직 처리되지 않았다면
80+
process(i, j, index);
81+
index += 1;
82+
}
83+
}
84+
}
85+
// 모든 인구 이동이 끝난 경우
86+
if (index == n * n) break;
87+
totalCount += 1;
88+
}
89+
90+
// 인구 이동 횟수 출력
91+
cout << totalCount << '\n';
92+
}

‎13/8.cpp

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
class Node {
6+
public:
7+
int pos1X;
8+
int pos1Y;
9+
int pos2X;
10+
int pos2Y;
11+
Node(int pos1X, int pos1Y, int pos2X, int pos2Y) {
12+
this->pos1X = pos1X;
13+
this->pos1Y = pos1Y;
14+
this->pos2X = pos2X;
15+
this->pos2Y = pos2Y;
16+
}
17+
};
18+
19+
vector<Node> getNextPos(Node pos, vector<vector<int> > board) {
20+
vector<Node> nextPos; // 반환 결과 (이동 가능한 위치들)
21+
// (상, 하, 좌, 우)로 이동하는 경우에 대해서 처리
22+
int dx[] = {-1, 1, 0, 0};
23+
int dy[] = {0, 0, -1, 1};
24+
for (int i = 0; i < 4; i++) {
25+
int pos1NextX = pos.pos1X + dx[i];
26+
int pos1NextY = pos.pos1Y + dy[i];
27+
int pos2NextX = pos.pos2X + dx[i];
28+
int pos2NextY = pos.pos2Y + dy[i];
29+
// 이동하고자 하는 두 칸이 모두 비어 있다면
30+
if (board[pos1NextX][pos1NextY] == 0 && board[pos2NextX][pos2NextY] == 0) {
31+
nextPos.push_back(Node(pos1NextX, pos1NextY, pos2NextX, pos2NextY));
32+
}
33+
}
34+
// 현재 로봇이 가로로 놓여 있는 경우
35+
int hor[] = {-1, 1};
36+
if (pos.pos1X == pos.pos2X) {
37+
for (int i = 0; i < 2; i++) { // 위쪽으로 회전하거나, 아래쪽으로 회전
38+
// 위쪽 혹은 아래쪽 두 칸이 모두 비어 있다면
39+
if (board[pos.pos1X + hor[i]][pos.pos1Y] == 0 && board[pos.pos2X + hor[i]][pos.pos2Y] == 0) {
40+
nextPos.push_back(Node(pos.pos1X, pos.pos1Y, pos.pos1X + hor[i], pos.pos1Y));
41+
nextPos.push_back(Node(pos.pos2X, pos.pos2Y, pos.pos2X + hor[i], pos.pos2Y));
42+
}
43+
}
44+
}
45+
// 현재 로봇이 가로로 놓여 있는 경우
46+
int ver[] = {-1, 1};
47+
if (pos.pos1Y == pos.pos2Y) {
48+
for (int i = 0; i < 2; i++) { // 왼쪽으로 회전하거나, 오른쪽으로 회전
49+
// 왼쪽 혹은 오른쪽 두 칸이 모두 비어 있다면
50+
if (board[pos.pos1X][pos.pos1Y + ver[i]] == 0 && board[pos.pos2X][pos.pos2Y + ver[i]] == 0) {
51+
nextPos.push_back(Node(pos.pos1X, pos.pos1Y, pos.pos1X, pos.pos1Y + ver[i]));
52+
nextPos.push_back(Node(pos.pos2X, pos.pos2Y, pos.pos2X, pos.pos2Y + ver[i]));
53+
}
54+
}
55+
}
56+
// 현재 위치에서 이동할 수 있는 위치를 반환
57+
return nextPos;
58+
}
59+
60+
int solution(vector<vector<int> > board) {
61+
// 맵의 외곽에 벽을 두는 형태로 맵 변형
62+
int n = board.size();
63+
vector<vector<int> > newBoard(n + 2, vector<int>(n + 2, 1));
64+
for (int i = 0; i < n; i++) {
65+
for (int j = 0; j < n; j++) {
66+
newBoard[i + 1][j + 1] = board[i][j];
67+
}
68+
}
69+
// 너비 우선 탐색(BFS) 수행
70+
queue<pair<Node, int> > q;
71+
vector<Node> visited;
72+
Node pos = Node(1, 1, 1, 2); // 시작 위치 설정
73+
q.push({pos, 0}); // 큐에 삽입한 뒤에
74+
visited.push_back(pos); // 방문 처리
75+
// 큐가 빌 때까지 반복
76+
while (!q.empty()) {
77+
Node pos = q.front().first;
78+
int cost = q.front().second;
79+
q.pop();
80+
// (n, n) 위치에 로봇이 도달했다면, 최단 거리이므로 반환
81+
if ((pos.pos1X == n && pos.pos1Y == n) || (pos.pos2X == n && pos.pos2Y == n)) {
82+
return cost;
83+
}
84+
// 현재 위치에서 이동할 수 있는 위치 확인
85+
vector<Node> nextPos = getNextPos(pos, newBoard);
86+
for (int i = 0; i < nextPos.size(); i++) {
87+
// 아직 방문하지 않은 위치라면 큐에 삽입하고 방문 처리
88+
bool check = true;
89+
Node pos = nextPos[i];
90+
for (int j = 0; j < visited.size(); j++) {
91+
if (pos.pos1X == visited[j].pos1X && pos.pos1Y == visited[j].pos1Y && pos.pos2X == visited[j].pos2X && pos.pos2Y == visited[j].pos2Y) {
92+
check = false;
93+
break;
94+
}
95+
}
96+
if (check) {
97+
q.push({pos, cost + 1});
98+
visited.push_back(pos);
99+
}
100+
}
101+
}
102+
return 0;
103+
}

0 commit comments

Comments
 (0)
Please sign in to comment.