是一道题的代码,求look找错
  • 板块学术版
  • 楼主wang0728
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/31 22:11
  • 上次更新2024/8/1 08:37:05
查看原帖
是一道题的代码,求look找错
738168
wang0728楼主2024/7/31 22:11

题目


本地运行没问题,提交就是CE

#include <bits/stdc++.h>
using namespace std;
struct f{
	int x,y;
};
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
int n,x1,y1,a[105][105],dis[105][105];
bool vis[105][105];
queue<f>q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>x1>>y1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) cin>>a[i][j];
	}
	q.push({1,1});
	vis[1][1]=true;
	while(!q.empty()){
		f s=q.front(); q.pop();
		if(s.x==x1 && s.y==y1){
			cout<<dis[s.x][s.y]; return 0;
		}
		for(int i=0;i<4;i++){
			int xx=dx[i]*a[s.x][s.y],yy=dy[i]*a[s.x][s.y];
			xx+=s.x; yy+=s.y;
			if(xx<=0 || xx>n || yy<=0 || yy>n) continue;
			if(vis[xx][yy]==false){
				dis[xx][yy]+=dis[s.x][s.y]+1;
				q.push({xx,yy});
				vis[xx][yy]=true;
			}
		}
	}
	cout<<"-1";
	return 0;
}
2024/7/31 22:11
加载中...