PS/BOJ C++
16173번 - 점프왕 쩰리 (Small)
zpqmdh
2022. 3. 20. 20:36
https://www.acmicpc.net/problem/16173
16173번: 점프왕 쩰리 (Small)
쩰리는 맨 왼쪽 위의 칸에서 출발해 (행, 열)로 나타낸 좌표계로, (1, 1) -> (2, 1) -> (3, 1) -> (3, 3)으로 이동해 게임에서 승리할 수 있다.
www.acmicpc.net
#include <iostream>
#include <queue>
using namespace std;
int N;
int Map[4][4];
bool isVisited[4][4];
int dy[2] = {0, -1};
int dx[2] = {1, 0};
void bfs()
{
queue<pair<int, int>> Q;
Q.push(make_pair(0,0));
isVisited[0][0] = true;
while(!Q.empty())
{
int y = Q.front().first;
int x = Q.front().second;
Q.pop();
int step = Map[y][x];
if(step == -1) //최종단계 도달
{
cout << "HaruHaru" << '\n';
return ;
}
//아래로
if(y+step < N && !isVisited[y+step][x])
{
Q.push(make_pair(y+step, x));
isVisited[y+step][x] = true;
}
//오른쪽으로
if(x+step < N && !isVisited[y][x+step])
{
Q.push(make_pair(y, x+step));
isVisited[y][x+step] = true;
}
}
cout << "Hing" << '\n';
return ;
}
int main()
{
cin >> N;
for(int i=0; i<N; i++)
{
for(int j=0; j<N; j++)
{
cin >> Map[i][j];
}
}
bfs();
return 0;
}