题目链接:​​传送门​

从每个点跑spfa
经过障碍距离就加一
看这条路径的长度是不是<=T

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define

using namespace std;
typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int v[B][B], n, m, t, mp[B][B], dis[B][B];
char opt; double ans;
void wbb(int x, int y) {
memset(v, 0, sizeof v);
memset(dis, 0x3f, sizeof dis);
queue<int> q1, q2; dis[x][y] = mp[x][y];
q1.push(x); q2.push(y);
while (!q1.empty()) {
int xx = q1.front(); q1.pop();
int yy = q2.front(); q2.pop();
v[xx][yy] = 0;
for (int i = 0; i < 4; i++) {
int fx = xx + dx[i];
int fy = yy + dy[i];
if (fx < 1 or fx > n or fy < 1 or fy > m) continue;
if (dis[fx][fy] > dis[xx][yy] + mp[fx][fy]) {
dis[fx][fy] = dis[xx][yy] + mp[fx][fy];
if (!v[fx][fy]) {
v[fx][fy] = 1;
q1.push(fx);
q2.push(fy);
}
}
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (dis[i][j] <= t)
ans = max(ans, sqrt((i - x) * (i - x) + (j - y) * (j - y)));
}

int main(int argc, char const *argv[]) {
cin >> n >> m >> t;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> opt;
if (opt == '0') mp[i][j] = 0;
else mp[i][j] = 1;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
wbb(i, j);
cout << fixed << setprecision(6) << ans << endl;
}