ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 2468번 C++ 풀이
    백준 2018. 11. 25. 23:29
    #include <iostream>
    #include <queue>
    #include <vector>
    using namespace std;
    int delta[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

    bool isVisited[101][101];
    int buffer[101][101];
    int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (auto i=0; i<n; i++){
    for (auto j=0; j<n; j++){
    cin >> buffer[i][j];
    }
    }
    int answer = 0;


    for (auto height = 0; height <= 100; height++ ){
    for (auto i=0; i<n; i++){
    for (auto j=0; j<n; j++){
    isVisited[i][j] = false;
    }
    }
    int safe_area = 0;
    for (auto i=0; i<n; i++){
    for (auto j=0; j<n; j++){
    if ( !isVisited[i][j] && (buffer[i][j] > height)){
    safe_area++;

    isVisited[i][j] = true;
    queue<pair<int, int>> q;
    q.push(make_pair(i,j));
    while (!q.empty()){

    auto top = q.front();
    q.pop();
    for (auto k=0; k<4; k++){
    auto next_x = top.first + delta[k][0];
    auto next_y = top.second + delta[k][1];

    if (0 <= next_x && next_x < n && 0 <= next_y && next_y < n){
    if (!isVisited[next_x][next_y] && (buffer[next_x][next_y] > height)){
    isVisited[next_x][next_y] = true;
    q.push(make_pair(next_x,next_y));
    }

    }
    }
    }

    }
    }
    }
    answer = max(answer,safe_area);

    }
    cout << answer;
    return 0;

    }


    '백준' 카테고리의 다른 글

    백준 11559번 C++ 코드  (0) 2019.08.29
    백준 2799번 C++ 풀이  (0) 2019.01.04
    백준 1707번 C++ 풀이  (0) 2018.11.25
    백준 14502번 C++ 풀이  (0) 2018.11.20
    백준 c++ 11053번 풀이  (0) 2018.11.19
Designed by Tistory.