Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- int main( ) {
- std::ios_base::sync_with_stdio(0);
- std::cin.tie(0);
- std::cout.tie(0);
- int r, c, k;
- std::cin >> r >> c >> k;
- std::pair<int, int> ini;
- char mapa[r][c];
- for (int i = 0; i < r; ++i) {
- for (int j = 0; j < c; ++j) {
- std::cin >> mapa[i][j];
- if (mapa[i][j] == '$') {
- ini.first = i, ini.second = j;
- }
- }
- }
- int inicio = 0, fin = 1;
- bool memo[r][c] = { };
- std::vector<std::pair<int, int>> cola;
- cola.push_back(ini);
- memo[ini.first][ini.second] = true;
- for (int f = 0; f < k; ++f) {
- for (int q = fin; inicio != q; ++inicio) {
- auto act = cola[inicio];
- 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}}) {
- int dx = it.first, dy = it.second;
- if (dx >= 0 && dx < r && dy >= 0 && dy < c && !memo[dx][dy] && mapa[dx][dy] != '#') {
- cola.push_back(it), ++fin;
- mapa[dx][dy] = '*';
- memo[dx][dy] = true;
- }
- }
- }
- }
- for (int i = 0; i < r; ++i) {
- for (int j = 0; j < c; ++j) {
- std::cout << mapa[i][j];
- }
- std::cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement