提交时间:2022-05-28 10:11:39

运行 ID: 993

#include<bits/stdc++.h> using namespace std; const int N = 205; char a[N][N]; struct zb{ int x, y, ckl; }; int m, n; int jl[N][N], xz[4] = {-1, 1, 0, 0}, yz[4] = {0, 0, -1, 1}; int main(){ int t, cx, cy; cin >> n >> m >> t; for(int i = 1;i <= n;i ++){ for(int j = 1;j <= m;j ++){ cin >> a[i][j]; if(a[i][j] == '@'){ cx = i; cy = j; } } } queue<zb> q; q.push({cx, cy, t}); while(!q.empty()){ int x = q.front().x, y = q.front().y, tmp = q.front().ckl; q.pop(); if(a[x][y] == '+'){ cout << jl[x][y]; break; } for(int i = 0;i < 4;i ++){ int dx = xz[i] + x, dy = yz[i] + y; if(dx >= 1 && dx <= n && dy >= 1 && dy <= m){ if(!tmp && a[dx][dy] == '#'){ continue; } if(a[dx][dy] == '#' && tmp){ q.push({dx, dy, tmp - 1}); jl[dx][dy] = jl[x][y] + 1; } else { q.push({dx, dy, tmp}); jl[dx][dy] = jl[x][y] + 1; } } } } }