为什么我的代码输出一行?
  • 板块P1238 走迷宫
  • 楼主mediocre_
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/8/31 10:03
  • 上次更新2023/10/27 13:00:14
查看原帖
为什么我的代码输出一行?
565707
mediocre_楼主2022/8/31 10:03
#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
int n,m,sx,sy,px,py;
int a[N][N];
bool nose[N][N];
void dfs(int x,int y,int q,int b[]){
	if (x == px && y == py){
		for (int i = 1;i <= q - 2;i += 2)
		    printf("(%d,%d)->",b[i],b[i + 1]);
		printf("(%d,%d)",px,py);
		printf("\n");
		return;
	}
	b[q] = x;
	b[q + 1] = y;
	if (!(x < 1 || y < 1 || x > n || y > m || nose[x][y] == true || a[x][y] == 0)){
		nose[x][y] = true;
		dfs(x,y - 1,q + 2,b);
		dfs(x - 1,y,q + 2,b);
		dfs(x,y + 1,q + 2,b);
		dfs(x + 1,y,q + 2,b);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= m;++j)
		    scanf("%d",&a[i][j]);
	scanf("%d%d%d%d",&sx,&sy,&px,&py);
	int b[N];
	dfs(sx,sy,1,b);
	return 0;
}
2022/8/31 10:03
加载中...