WA on #5 #6 求调
查看原帖
WA on #5 #6 求调
1162628
Lanpinye_Only楼主2024/8/7 09:46
#include<bits/stdc++.h>
#define N 128
using namespace std;
struct xy {
	int x, y;
};
int dx[5] = {0, 1, 0, -1, 0};
int dy[5] = {0, 0, 1, 0, -1};
char w[N][N];
bool vis[N][N];
xy path[N];
int n, m;
void dfs(int x, int y, int t) {
	if (x == n && y == m) {
		cout<<"1 1\n";
		for (int i = 0; i < t; i++) {
			cout << path[i].x <<" "<< path[i].y << '\n';
		}
		return;
	}
	for (int i = 1; i <= 4; i++) {
		int tx = x + dx[i];
		int ty = y + dy[i];
		if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && !vis[tx][ty] && w[tx][ty] == '.') {
			path[t].x = tx;
			path[t].y = ty;
			vis[tx][ty] = 1;
			dfs(tx, ty, t + 1);
			path[t].x = 0;
			path[t].y = 0;
		
		}
	}
}
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> w[i][j];
		}
	}
	vis[1][1]=1;
	dfs(1,1,0);
}
2024/8/7 09:46
加载中...