P6207 [USACO06OCT] Cows on Skates G
作者:
jy9
,
2024-12-12 22:23:47
,
所有人可见
,
阅读 2
#include <iostream>
using namespace std;
const int N = 114;
int r, c;
char mp[N][N];
bool st[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
struct node{
int x, y;
} a[100010];
//bool flag = 0;
int cnt;
void dfs(int x, int y){
if(x == r && y == c){
cout << 1 << ' ' << 1 << endl;
for (int i = 1; i <= cnt; i ++ ){
cout << a[i].x << ' ' << a[i].y << endl;
}
//flag = 1;
//return;
exit(0);
}
//if(flag) return;
for (int i = 0; i < 4; i ++ ){
int xx = x + dx[i];
int yy = y + dy[i];
if(st[xx][yy]) continue;
if(xx < 1 || xx > r || yy < 1 || yy > c) continue;
if(mp[xx][yy] == '*') continue;
st[xx][yy] = 1;
cnt++;
a[cnt].x = xx;
a[cnt].y = yy;
dfs(xx, yy);
cnt --;
}
}
int main()
{
cin >> r >> c;
for (int i = 1; i <= r; i ++ ){
for (int j = 1; j <= c; j ++ ){
cin >> mp[i][j];
}
}
st[1][1] = 1;
dfs(1, 1);
return 0;
}