본문 바로가기

Algorithm/BAEKJOON

[BOJ] 16173번 점프왕 쩰리 (Small) (C++)

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
반응형