求助广搜,悬一关
  • 板块学术版
  • 楼主ztyo_zysclown
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/10/18 15:25
  • 上次更新2023/11/2 13:04:58
查看原帖
求助广搜,悬一关
947854
ztyo_zysclown楼主2023/10/18 15:25

题目

#include<bits/stdc++.h>
using namespace std;
int a[1100][1100];
int b[110000][3];
bool op[1010][1010];
int qwe[1010][1010];
int fx[5]={0,0,1,0,-1};
int fy[5]={0,1,0,-1,0};
int n,tx,ty;
int xa,ya,xb,yb;
int head=1,rear=1;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			char s;
			cin>>s;
			a[i][j]=s-'0';
		} 
	}
	cin>>xa>>ya>>xb>>yb;
	b[1][1]=xa;
	b[1][2]=ya;
	op[xa][ya]=true;
	while(head<=rear){
		for(int i=1;i<=4;i++){
			tx=b[head][1]+fx[i];
			ty=b[head][2]+fy[i];
			if(tx>=1&&tx<=n&&ty>=1&&ty<=n&&a[tx][ty]!=1&&op[tx][ty]==false){
				rear++;
				qwe[tx][ty]=qwe[b[head][1]][b[head][2]]+1;
				op[tx][ty]=true;
				b[rear][1]=tx;
				b[rear][2]=ty;
			}
		}
		head++;
	}
	cout<<qwe[xb][yb];
	return 0;
}

评测记录

2023/10/18 15:25
加载中...