#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#include <stdio.h>
#include <math.h>
#include <sstream>
#include<cassert>
#include <climits>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
#define MAXV 987654321
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using iis = pair<int, string>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;
bool visited[2005][2005];
vector<string> maps(2005);
queue<int> q;
// 위 아래 오른쪽 왼쪽
int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };
int startx = -1, starty = -1, endx = -1, endy = -1;
int n, m;
void dfs(int y, int x)
{
visited[y][x] = true;
if (y == endx && x == endy) {
printf("find\n");
return;
}
for (int i = 0; i < 4; i++)
{
if (x + dx[i] < 0 || m <= x + dx[i])
continue;
if (y + dy[i] < 0 || n <= y + dy[i])
continue;
if (maps[y + dy[i]][x + dx[i]] == '+')
continue;
if (visited[y + dy[i]][x + dx[i]])
continue;
q.push()
dfs(y + dy[i], x + dx[i]);
}
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
memset(visited, false, sizeof(visited));
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> maps[i];
// 세로줄에서 시작점 찾기
for (int i = 0; i < n; i++) {
if (maps[i][0] == '.') {
if(startx == -1 && starty == -1) {
startx = i;
starty = 0;
} else {
endx = i;
endy = 0;
}
}
if (maps[i][m-1] == '.') {
if (startx == -1 && starty == -1) {
startx = i;
starty = m-1;
} else {
endx = i;
endy = m-1;
}
}
}
// 가로줄에서 시작점 찾기
for (int i = 0; i < m; i++) {
if (maps[0][i] == '.') {
if(startx == -1 && starty == -1) {
startx = 0;
starty = i;
} else {
endx = 0;
endy = i;
}
}
if (maps[n-1][i] == '.') {
if (startx == -1 && starty == -1) {
startx = n-1;
starty = i;
} else {
endx = n-1;
endy = i;
}
}
}
// 시작점 초기화 끝
cout << startx << " " << starty << "\n" << endx << " " << endy << "\n\n";
dfs(startx, starty);
return 0;
}
카테고리 없음