求助
  • 板块学术版
  • 楼主hkl99
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/7/30 20:14
  • 上次更新2024/7/30 21:25:05
查看原帖
求助
770439
hkl99楼主2024/7/30 20:14

P1746 离开中山路

在DEV c++上编译没错,但提交却说编译错误,这是为啥

悬赏一个关注

代码:

#include<bits/stdc++.h>
using namespace std;
int n,fx[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int a[1010][1010],b[1010][1010];
int x1,x2,y1,y2;
struct node{
	int x,y,step;
};
void bfs(int x,int y){
	queue <node> q;
	node t;
	t.x=x;
	t.y=y;
	t.step=0;
	a[x][y]=1;
	q.push(t);
	while(!q.empty()){
		t=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int nx=t.x+fx[i][1];
			int ny=t.y+fx[i][0];
			if(nx==x2&&ny==y2){
				cout<<t.step+1;
				return;
			}
			if(nx>=1&&nx<=n&&ny>=1&&ny<=n&&a[nx][ny]==0){
				a[nx][ny]=1;
				node tt;
				tt.x=nx;
				tt.y=ny;
				tt.step=t.step+1;
				q.push(tt);
			}
		}
	}
	return ;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%1d",&b[i][j]);
			a[i][j]=b[i][j];
		}
	}
	cin>>x1>>y1>>x2>>y2;
	bfs(x1,y1);
	return 0;
}

2024/7/30 20:14
加载中...