Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- DirectX11
- winapi
- 언리얼엔진5
- C++
- 팰린드롬 만들기
- Unreal Engine5
- baekjoon
- Frustum
- 1563
- IFileDialog
- GeeksForGeeks
- 티스토리챌린지
- UnrealEngine5
- 프로그래머스
- Programmers
- UE5
- const
- 줄 세우기
- 백준
- 2294
- DeferredRendering
- 오블완
- C
- algorithm
- softeer
- UnrealEngine4
- RVO
- NRVO
- RootMotion
- directx
Archives
- Today
- Total
Game Develop
[Algorithm] Programmers :: 무인도 여행 본문
https://school.programmers.co.kr/learn/courses/30/lessons/154540
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
|
struct Node
{
int y;
int x;
};
vector<string> arr;
int arrRow;
int arrCol;
int dir[4][2] = { {-1,0}, {1,0}, {0,-1}, {0,1} };
int BFS(int startY, int startX)
{
int result = 0;
queue<Node> q;
q.push({ startY,startX });
result += arr[startY][startX] - '0';
arr[startY][startX] = 'X';
while (!q.empty())
{
int curY = q.front().y;
int curX = q.front().x;
q.pop();
for (int i = 0; i < 4; ++i)
{
int nextY = curY + dir[i][0];
int nextX = curX + dir[i][1];
if (nextY < 0 || nextY >= arrRow) continue;
if (nextX < 0 || nextX >= arrCol) continue;
if (arr[nextY][nextX] == 'X') continue;
result += arr[nextY][nextX] - '0';
arr[nextY][nextX] = 'X';
q.push({ nextY,nextX });
}
}
return result;
}
vector<int> solution(vector<string> maps) {
vector<int> answer;
arr = maps;
arrRow = maps.size();
arrCol = maps[0].size();
for (int i = 0; i < arrRow; ++i)
{
for (int j = 0; j < arrCol; ++j)
{
if (arr[i][j] != 'X')
{
int temp = BFS(i, j);
answer.push_back(temp);
}
}
}
sort(answer.begin(), answer.end());
if (answer.size() == 0)
{
answer.push_back(-1);
}
return answer;
}
|
cs |
기본적인 탐색문제.
'Algorithm > Programmers' 카테고리의 다른 글
[Algorithm] Programmers :: 인사고과 (0) | 2023.02.07 |
---|---|
[Algorithm] Programmers :: 두 큐 합 같게 만들기 (1) | 2023.02.02 |
[Algorithm] Programmers :: 순위 (0) | 2023.01.17 |
[Algorithm] Programmers :: 등산코스 정하기 (0) | 2023.01.16 |
[Algorithm] Programmers :: 길 찾기 게임 (0) | 2022.10.12 |