Cows on Skates
hnahongyi
2023-11-18 10:23:29
#include<bits/stdc++.h>
using namespace std;
int r, c, sum = 0;
const int N = 200;
bool used[N][N];
char g[N][N];
struct ss {
int x, y;
};
ss arr[N];
int dx[5] = {0, 1, 0, -1};
int dy[5] = {1, 0, -1, 0};
inline bool check(int a, int b) {
if (a < 1 || a > r || b < 1 || b > c || used[a][b] == false)
return false;
else
return true;
}
void dfs(int a, int b) {
if (a == r && b == c) {
for (int i = 0; i < sum; i++)
printf("%d %d\n", arr[i].x, arr[i].y);
//exit(0);
return ;
} else {
int tx, ty;
for (int i = 0; i < 4; i++) {
tx = a + dx[i];
ty = b + dy[i];
if (check(tx, ty)) {
arr[sum].x = tx;
arr[sum].y = ty;
sum++;
used[tx][ty] = false;
dfs(tx, ty);
sum--;
}
}
}
}
int main() {
cin >> r >> c;
for (int i = 1; i <= r; i++) {
scanf("%s", g[i] + 1);
for (int j = 1; j <= c; j++) {
if (g[i][j] == '*')
used[i][j] = false;
else
used[i][j] = true;
}
}
cout << "1 1" << endl;
dfs(1, 1);
return 0;
}