离谱的 0pts
  • 板块P1238 走迷宫
  • 楼主wky_wsy_
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/9 22:35
  • 上次更新2025/1/10 15:16:54
查看原帖
离谱的 0pts
1323415
wky_wsy_楼主2025/1/9 22:35

很离谱的结果,输出的东西长度都是对的,但是每次输出的具体坐标全错。。

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;
int n,m,fx,fy,ex,ey;
int a[20][20];
int lu[9007][2];
inline void out(int k){
	for(int i=1;i<=k;i++){
		printf("(%lld, %lld)",a[i][0],a[i][1]);
		if(i!=k) printf("->");
	}
}
void dfs(int x,int y,int k){
	if(x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]==1){
		lu[k][0]=x;
		lu[k][1]=y;
		a[x][y]=0;
		dfs(x,y-1,k+1);
		dfs(x-1,y,k+1);
		dfs(x,y+1,k+1);
		dfs(x+1,y,k+1);
		a[x][y]=1;
	}
	if(x==ex&&y==ey){
		out(k);
		cout<<endl;
		return ;
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	cin>>fx>>fy>>ex>>ey;
	dfs(fx,fy,0);
	return 0;
}

2025/1/9 22:35
加载中...