站外题求助,炸了一个点
  • 板块学术版
  • 楼主butterbread
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/2/26 09:07
  • 上次更新2023/10/23 23:44:39
查看原帖
站外题求助,炸了一个点
553981
butterbread楼主2023/2/26 09:07

题目来源
代码:

#include<bits/stdc++.h>
using namespace std;
struct node {
	int pt;
	int xp;
	int yp;
};
node a[101][101];
int n,sx,sy,ex,ey,cnt,d[2][4]= {{0,1,0,-1},{-1,0,1,0}};
queue <node> q;
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			scanf("%d",&a[i][j].pt);
			a[i][j].xp=i;
			a[i][j].yp=j;
		}
	}
	scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
	q.push(a[sx][sy]);
	a[sx][sy].pt++;
	while(!q.empty()) {
		if(q.front().xp==a[ex][ey].xp&&q.front().yp==a[ex][ey].yp){
			cout<<"YES"<<endl;
			exit(0);
		}
		for(int i=0; i<4; i++) {
			int fx=q.front().xp+d[0][i];
			int fy=q.front().yp+d[1][i];
			if(fx>0&&fx<=n&&fy>0&&fy<=n&&a[fx][fy].pt==0){
				a[fx][fy].pt++;
				q.push(a[fx][fy]);
			}
		}
		q.pop();
	}
	cout<<"NO"<<endl;
	return 0;
}
2023/2/26 09:07
加载中...