样例没过求调
查看原帖
样例没过求调
1181602
Cute_Furina楼主2024/8/23 16:22
#include<bits/stdc++.h>
using namespace std;
int n, m, a[200][200], b[200][200];
char c;
int x2[5] = {0, 1, -1, 0, 0};
int y2[5] = {0, 0, 0, 1, -1};
void dfs(int x, int y) {
	cout << x << " " << y << endl;
	if(x == n && y == m) {
		return ;
	}
	for(int i = 1;i <= 4;i ++) {
		int xx = x + x2[i], yy = y + y2[i];
		if(a[xx][yy]) {
			a[x][y] = 0;
			dfs(xx, yy);
		}
	}
}
int main() {
	cin >> n >> m;
	for(int i = 1;i <= n;i ++) {
		for(int j = 1;j <= n;j ++) {
			cin >> c;
			if(c == '.') a[i][j] = 1;
		}
	}
	dfs(1, 1);
	return 0;
}
2024/8/23 16:22
加载中...