#include <iostream>
#include <vector>
using namespace std;
int BFS[10000000][2];
int de = 0;
int qu = 0;
void push(int y, int x) {
BFS[qu][0] = y;
BFS[qu++][1] = x;
return;
}
int pop(vector<int> v) {
if (de > qu)
return -1;
v[0] = BFS[de][0];
v[1] = BFS[de++][1];
return 0;
}
int solution(vector<vector<int>> maps) {
cout << "go" << endl;
int n = maps.size(), m = maps[0].size();
push(0, 0);
int answer = 0;
int by = 1;
int keep = 0;
while (1) {
vector<int> v(3);
if (pop(v) == -1)
return -1;
if (by == 0) {
answer++;
by = keep;
keep = 0;
}
by--;
if (v[0] == n - 1 && v[1] == m - 1)
return answer;
if (v[0] < 0 || v[0] >= n || v[1] < 0 || v[1] >= m)
continue;
if (maps[v[0]][v[1]] == 0)
continue;
maps[v[0]][v[1]] = 0;
keep += 4;
push(v[0] + 1, v[1]);
push(v[0] - 1, v[1]);
push(v[0], v[1] + 1);
push(v[0], v[1] - 1);
}
return 0;
}
int main(void) {
vector<vector<int>> maps(100000, vector<int>(100000));
maps = {{1, 0, 1, 1, 1},
{1, 0, 1, 0, 1},
{1, 0, 1, 1, 1},
{1, 1, 1, 0, 1},
{0, 0, 0, 0, 1}};
cout << solution(maps);
}
top of page
실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
수정: 4월 11일
게임 맵 최단거리(미완)
게임 맵 최단거리(미완)
댓글 0개
좋아요
댓글(0)
bottom of page