warm_sun @ 2019-09-04 21:06:33
样例过了, 但是提交0分,实在不知道错哪里了
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int N = 1e4 + 5;
int n, f[N][N], map[N][N];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool book[N][N];
char ab[N];
void bfs(int a, int b){
queue <int> qx;
queue <int> qy;
qx.push(a);
qy.push(b);
book[a][b] = 1;
f[a][b] = 0;
while(!qy.empty()){
int xx = qx.front();
int yy = qy.front();
qx.pop(); qy.pop();
for(int i=0; i<4; ++i){
int x = xx + dx[i];
int y = yy + dy[i];
if(x>=1&&x<=n&&y>=1&&y<=n&&!book[x][y]&&!map[x][y]){
qx.push(x);
qy.push(y);
f[x][y] = f[xx][yy] + 1;
book[x][y] = 1;
}
}
}
}
int main(){
int x, y, xx, yy;
scanf("%d", &n);
for(int i=1; i<=n; ++i){
scanf("%s", ab+1);
for(int j=1; j<=n; ++j){
map[i][j] = ab[i] - '0';
}
}
scanf("%d%d%d%d", &x, &y, &xx, &yy);
bfs(x, y);
printf("%d\n", f[xx][yy]);
return 0;
}
by warm_sun @ 2019-09-04 21:15:59
我 j 写成了 i
by warm_sun @ 2019-09-04 21:16:16
[ 捂脸 ]