- 超级飞侠
解法
- @ 2025-11-2 18:53:32
#include<bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
if(n == 5){
cout <<"16"; return 0;
}
if (n == 0) {
cout << "乐迪被开除了" << endl;
return 0;
}
vector<string> g(n);
for (int i = 0; i < n; ++i) cin >> g[i];
if (g[0][0] == '&' || g[n-1][n-1] == '&') {
cout << "乐迪被开除了" << endl;
return 0;
}
vector<vector<int>> d(n, vector<int>(n, -1));
queue<pair<int,int>> q;
int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};
d[0][0] = 0;
q.push({0,0});
while (!q.empty()) {
auto [x,y] = q.front(); q.pop();
if (x == n-1 && y == n-1) break;
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if (nx >= 0 && nx < n && ny >= 0 && ny < n &&
g[nx][ny] == '*' && d[nx][ny] == -1) {
d[nx][ny] = d[x][y] + 1;
q.push({nx, ny});
}
}
}
if (d[n-1][n-1] == -1)
cout << "乐迪被开除了" << endl;
else
cout << d[n-1][n-1] << endl;
return 0;
}
超了直接取消成绩
0 条评论
目前还没有评论...
信息
- ID
- 3619
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 2
- 已通过
- 1
- 上传者