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 | 
                            Tags
                            
                        
                          
                          - Programmers
 - 팰린드롬 만들기
 - UnrealEngine4
 - GeeksForGeeks
 - 1563
 - Frustum
 - 백준
 - C
 - IFileDialog
 - 프로그래머스
 - 오블완
 - directx
 - 줄 세우기
 - 티스토리챌린지
 - UE5
 - 언리얼엔진5
 - UnrealEngine5
 - RootMotion
 - C++
 - 2294
 - DirectX11
 - NRVO
 - baekjoon
 - softeer
 - Unreal Engine5
 - algorithm
 - winapi
 - RVO
 - const
 - TObjectPtr
 
                            Archives
                            
                        
                          
                          - Today
 
- Total
 
Game Develop
[Algorithm] Baekjoon 2468번 : 안전 영역 본문
https://www.acmicpc.net/problem/2468
2468번: 안전 영역
재난방재청에서는 많은 비가 내리는 장마철에 대비해서 다음과 같은 일을 계획하고 있다. 먼저 어떤 지역의 높이 정보를 파악한다. 그 다음에 그 지역에 많은 비가 내렸을 때 물에 잠기지 않는
www.acmicpc.net
| 
 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 | 
          