输出乱码,求调
查看原帖
输出乱码,求调
1002517
Adorable_楼主2024/8/13 18:31
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
const int N = 1e3+5;
int n,ans,sx,sy,ex,ey,maps[N][N];
int dx[5] = {0,0,1,-1},
	dy[5] = {1,-1,0,0}; 
bool b[N][N];
struct point
{
	int x,y;
};
queue<point> q;

int bfs()
{
	q.push({sx-1,sy-1});
	b[sx-1][sy-1] = 1;
	while(!q.empty())
	{
		point p;
		p = q.front();
		q.pop();
		if(p.x == ex-1 and p.y == ey-1) return maps[p.x][p.y];
		for(int i = 0;i<4;i++) 
		{
			int xx = p.x+dx[i],yy = p.y+dy[i];
//			cout<<xx<<' '<<yy<<endl;
			if(xx<0 or xx>=n or yy<0 or yy>=n or b[xx][yy] or maps[yy]) continue;
//			cout<<'!'<<xx<<' '<<yy<<endl;
			b[xx][yy] = 1;
			maps[xx][yy] = maps[p.x][p.y] + 1;
		}
	}
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	memset(maps,0,sizeof(maps));
	cin>>n;
	for(int i = 0;i<n;i++)
		for(int j = 0;j<n;j++)
		{
			char c;
			cin>>c;
			maps[i][j] = c-'0';
		}
	cin>>sx>>sy>>ex>>ey;
	cout<<bfs()<<endl;
	return 0;
} 
2024/8/13 18:31
加载中...