ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 14502번 C++ 풀이
    백준 2018. 11. 20. 20:38

    문제가 요상하게 틀려서 브레이크포인트 고치면서 디버깅했습니다.

    하지만 브레이크포인트로는 힙의 밸류를 찍어주지 않더군요.


    LLDB에서 직접 확인해서 디버깅했습니다.



    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <climits>
    #include <string>
    #include <map>
    using namespace std;
    int n, m;

    int buffer[9][9];
    int temp[9][9];
    int delta[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    int maxVirus;
    int findVirus(){
    for (auto y=0; y<n; y++){
    for (auto x= 0; x<m; x++){
    temp[x][y] = buffer[x][y];
    // cout << buffer[x][y] << ' ';
    }
    // cout << '\n';
    }
    // cout << '\n';
    int virus = 0;

    for (auto y=0; y<n; y++){
    for (auto x=0; x<m; x++){
    if (temp[x][y] == 2){
    temp[x][y] = 3;
    virus++;
    queue<pair<int, int>> q;
    q.push(make_pair(x,y));
    while (!q.empty()){
    pair<int, int> top = q.front();
    q.pop();
    for (auto i=0; i<4; i++){
    int nextX = top.first + delta[i][0];
    int nextY = top.second + delta[i][1];

    if ( 0 <= nextX && nextX < m &&
    0 <= nextY && nextY <n){
    if (temp[nextX][nextY] == 2 || temp[nextX][nextY] == 0){
    temp[nextX][nextY] = 3;
    virus++;
    q.push(make_pair(nextX, nextY));
    }
    }
    }
    }
    }
    }
    }
    return virus;
    }
    void fillWall(int x, int y, int wall){
    if (wall == 3){
    maxVirus = min(maxVirus, findVirus());
    return;
    }

    if (x == m) {
    x = 0;
    y++;
    }
    while ( y != n){

    if (buffer[x][y] == 0){
    buffer[x][y] = 1;
    fillWall(x+1, y, wall+1);
    buffer[x][y] = 0;
    }

    x++;
    if (x == m) {
    x = 0;
    y++;
    }
    }

    }
    int main(){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    int blocknumber = 0;
    for (auto y=0; y<n; y++){
    for (auto x=0; x<m; x++){
    cin >> buffer[x][y];
    if (buffer[x][y] == 1 ) blocknumber++;
    }
    }
    maxVirus = INT_MAX;
    fillWall(0,0,0);
    // cout << blocknumber << '\n';
    // cout << maxVirus << '\n';
    cout << n*m -3 -blocknumber - maxVirus;

    return 0;
    }


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

    백준 2468번 C++ 풀이  (0) 2018.11.25
    백준 1707번 C++ 풀이  (0) 2018.11.25
    백준 c++ 11053번 풀이  (0) 2018.11.19
    백준 11057번 c++ 풀이  (0) 2018.11.18
    백준 1764번 c++ 풀이  (0) 2018.11.18
Designed by Tistory.