Sicosuki @ 2023-03-23 12:48:43
得了70分,有几个数据死活过不去,没有输出。 代码:
#include <iostream>
#include <queue>
using namespace std;
bool t[1005][1005];
int s[1005][1005];
int main()
{
int n,bx,by,fx,fy;
cin >> n;
char a[n+1][n+1];
for(int i = 1; i <= n; i++)
for(int i2 = 1; i2 <= n; i2++)
cin >> a[i][i2];
cin >> bx >> by >> fx >> fy;
queue <int> x,y;
x.push(bx),y.push(by);
t[by][bx] = 1;
while(!x.empty())
{
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
for(int i = 0; i < 4; i++)
{
int ux = x.front() + dx[i];
int uy = y.front() + dy[i];
if(1 <= ux && ux <= n && 1 <= uy && uy <= n && t[uy][ux] == 0 && a[uy][ux] == '0')
{
x.push(ux),y.push(uy);
s[uy][ux] = s[y.front()][x.front()] + 1;
t[uy][ux] = 1;
if(ux == fx && uy == fy)
{
cout << s[uy][ux];
return 0;
}
}
}
x.pop(),y.pop();
}
if (t[fy][fx] == 0) {
cout << "无法到达终点";
}
}
无法通过的数据:
10
0100110100
0001110010
1000000001
1000100011
0000101100
1000001100
1001010011
B000010100
0101010000
1001000001
1 7 10 2
正确输出:
14
实际上没输出
by Sicosuki @ 2023-03-23 12:49:29
严格意义上来说输出的是“无法到达终点”
by _Initialize_ @ 2023-05-09 21:22:55
把前面开始点跟结束点x y坐标反一下应该就好了,我是这样错的
by Sicosuki @ 2023-05-28 10:38:00
@zhangshichen123456 过了过了,谢谢大佬