社区讨论
自己只是对第一个题解稍微改了一下,为啥就只有6分,求大佬帮助
P1825[USACO11OPEN] Corn Maze S参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @m5rxr6of
- 此快照首次捕获于
- 2025/01/11 16:40 去年
- 此快照最后确认于
- 2025/01/11 20:57 去年
CPP
#include<iostream>
#include<queue>
using namespace std;
int step[400][400];
queue<pair<int,int>>c;
char a[400][400];
bool vis[400][400];
int n, m;
int d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int sx, sy;
void goto_another(int &nx, int &ny) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (a[i][j] == a[nx][ny] && (i != nx || j != ny)) {
nx = i;
ny = j;
return;
}
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
if (a[i][j] == '@') {
sx = i;
sy = j;
}
}
}
c.push({sx, sy});
vis[sx][sy] = true;
step[sx][sy]=0;
while (!c.empty()) {
int dx=c.front().first;
int dy=c.front().second;
c.pop();
if (a[dx][dy] == '=') {
cout << step[dx][dy] << endl;
return 0;
}
if (a[dx][dy] >= 'A' && a[dx][dy] <= 'Z') {
goto_another(dx, dy);
}
for (int i = 0; i < 4; ++i) {
int nx = dx + d[i][0];
int ny = dy + d[i][1];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && a[nx][ny] != '#' && !vis[nx][ny]) {
vis[nx][ny] = true;
c.push({nx,ny});
step[nx][ny]=step[dx][dy]+1;
}
}
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...