Advertisement
AlejandroGY

Untitled

Aug 1st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. int main( ) {
  4.    std::ios_base::sync_with_stdio(0);
  5.    std::cin.tie(0);
  6.    std::cout.tie(0);
  7.  
  8.    int r, c, k;
  9.    std::cin >> r >> c >> k;
  10.  
  11.    std::pair<int, int> ini;
  12.    char mapa[r][c];
  13.    for (int i = 0; i < r; ++i) {
  14.       for (int j = 0; j < c; ++j) {
  15.          std::cin >> mapa[i][j];
  16.          if (mapa[i][j] == '$') {
  17.             ini.first = i, ini.second = j;
  18.          }
  19.       }
  20.    }
  21.  
  22.    int inicio = 0, fin = 1;
  23.    bool memo[r][c] = { };
  24.    std::vector<std::pair<int, int>> cola;
  25.  
  26.    cola.push_back(ini);
  27.    memo[ini.first][ini.second] = true;
  28.  
  29.    for (int f = 0; f < k; ++f) {
  30.       for (int q = fin; inicio != q; ++inicio) {
  31.          auto act = cola[inicio];
  32.  
  33.          for (auto it : std::initializer_list<std::pair<int, int>> {{act.first + 1, act.second}, {act.first - 1, act.second}, {act.first, act.second + 1}, {act.first, act.second - 1}}) {
  34.             int dx = it.first, dy = it.second;
  35.             if (dx >= 0 && dx < r && dy >= 0 && dy < c && !memo[dx][dy] && mapa[dx][dy] != '#') {
  36.                cola.push_back(it), ++fin;
  37.                mapa[dx][dy] = '*';
  38.                memo[dx][dy] = true;
  39.             }
  40.          }
  41.       }
  42.    }
  43.  
  44.    for (int i = 0; i < r; ++i) {
  45.       for (int j = 0; j < c; ++j) {
  46.          std::cout << mapa[i][j];
  47.       }
  48.       std::cout << "\n";
  49.    }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement