728x90
반응형
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 arr[3][3];
string bfs(){
queue<pair<int, int>> q;
q.push({0, 0});
while(!q.empty()){
int x = q.front().first;
int y = q.front().second;
int step = arr[x][y];
q.pop();
if(step == -1) return "HaruHaru";
if(step == 0) continue;
if(x + step < n) q.push({x + step, y});
if(y + step < n) q.push({x, y + step});
}
return "Hing";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> arr[i][j];
}
}
cout << bfs() << endl;
return 0;
}
728x90
반응형
'Algorithm > BAEKJOON' 카테고리의 다른 글
[BOJ] 4949번 균형잡힌 세상 (C++) (0) | 2022.07.29 |
---|---|
[BOJ] 2805번 나무 자르기 (C++) (0) | 2022.07.29 |
[BOJ] 2960번 에라토스테네스의 체 (C++) (0) | 2022.07.02 |
[C++] 16935번 배열 돌리기 3 (C++) (0) | 2022.07.01 |
[BOJ] 1235번 학생 번호 (C++) (0) | 2022.07.01 |