Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
982 | yy019 | 鸣人与佐助 | C++ | 内存超限 | 244 MS | 131112 KB | 1065 | 2022-05-28 10:05:03 |
#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 >> m >> n >> t; for(int i = 1;i <= m;i ++){ for(int j = 1;j <= n;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; } } } } }