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
- softeer
- Programmers
- C
- RootMotion
- DeferredRendering
- 티스토리챌린지
- UnrealEngine4
- 언리얼엔진5
- Frustum
- baekjoon
- 1563
- algorithm
- GeeksForGeeks
- winapi
- DirectX11
- 오블완
- 프로그래머스
- 줄 세우기
- 팰린드롬 만들기
- 백준
- Unreal Engine5
- UnrealEngine5
- C++
- directx
- 2294
- RVO
- const
- IFileDialog
- UE5
- NRVO
Archives
- Today
- Total
Game Develop
[Algorithm] Baekjoon 2468번 : 안전 영역 본문
https://www.acmicpc.net/problem/2468
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
|
int n;
int arr[101][101];
int tempMap[101][101];
int dir[4][2] = { {-1,0}, {1,0}, {0,-1}, {0,1} };
bool visited[101][101];
struct Node
{
int y;
int x;
};
void BFS(int startY, int startX, int maxHeight) // maxHeight 초과의 영역 개수.
{
queue<Node> q;
q.push({ startY, startX });
visited[startY][startX] = true;
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 >= n) continue;
if (nextX < 0 || nextX >= n) continue;
if (tempMap[nextY][nextX] <= maxHeight) continue;
if (visited[nextY][nextX]) continue;
visited[nextY][nextX] = true;
q.push({ nextY,nextX });
}
}
}
int getSafeZoneCount(int maxHeight) // maxHeight 미만은 물에 잠김.
{
memcpy(tempMap, arr, sizeof(tempMap));
memset(visited, false, sizeof(visited));
int safeCount = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (visited[i][j] || tempMap[i][j] <= maxHeight) continue;
BFS(i, j, maxHeight);
++safeCount;
}
}
return safeCount;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
int result = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
cin >> arr[i][j];
}
}
for (int i = 0; i <= 100; ++i)
{
result = max(result, getSafeZoneCount(i));
}
cout << result;
}
|
cs |
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm] Baekjoon 9205번 : 맥주 마시면서 걸어가기 (0) | 2023.02.13 |
---|---|
[Algorithm] Baekjoon 2573번 : 빙산 (0) | 2023.02.13 |
[Algorithm] Baekjoon 5014번 : 스타트링크 (0) | 2023.02.08 |
[Algorithm] Baekjoon 2644번 : 촌수계산 (0) | 2023.02.08 |
[Algorithm] Baekjoon 1309번 : 동물원 (1) | 2023.02.01 |