RE on #3
查看原帖
RE on #3
1201348
int_inf楼主2025/1/20 10:30

dalao求调,为啥会re

#include<bits/stdc++.h>
using namespace std;
int n,m,sx,sy,gx,gy,q[100001][3],st[1001][1001],dx[]={0,1,0,-1},dy[]={1,0,-1,0}; 
char c[1001][1001];
inline void bfs()
{
	int head=1,tail=1;
	while(head<=tail)
	{
		for(int i=0;i<4;i++)
		{
			int tx=q[head][1]+dx[i],ty=q[head][2]+dy[i];
			if(tx==gy&&ty==gx)
			{
				cout<<st[q[head][1]][q[head][2]]+1<<endl;
				exit(0);
			}
			if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&c[tx][ty]=='.')
			{
				tail++;
				q[tail][1]=tx,q[tail][2]=ty,st[tx][ty]=st[q[head][1]][q[head][2]]+1;
			}
		}
		head++;
	}
	
}
int main()
{
	cin>>n>>m>>sy>>sx>>gy>>gx;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>c[i][j];
		}
	}
	q[1][1]=sy,q[1][2]=sx,st[sy][sx]=0,c[sy][sx]='#'; 
	bfs();
	return 0;
}
2025/1/20 10:30
加载中...