Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 그래프
- 우선순위 큐
- 투 포인터
- Unreal Engine 5
- 시뮬레이션
- Team Fortress 2
- 다이나믹 프로그래밍
- 구현
- 트리
- 브루트포스
- BFS
- 자료구조
- 유니온 파인드
- 재귀
- 백준
- 다익스트라
- 문자열
- 알고리즘
- XR Interaction Toolkit
- 수학
- 정렬
- 스택
- VR
- 백트래킹
- 누적 합
- DFS
- c++
- ue5
- 유니티
- 그리디 알고리즘
Archives
- Today
- Total
1일1알
백준 11060번 점프 점프 C++ 본문
https://www.acmicpc.net/problem/11060
11060번: 점프 점프
재환이가 1×N 크기의 미로에 갇혀있다. 미로는 1×1 크기의 칸으로 이루어져 있고, 각 칸에는 정수가 하나 쓰여 있다. i번째 칸에 쓰여 있는 수를 Ai라고 했을 때, 재환이는 Ai이하만큼 오른쪽으로
www.acmicpc.net
bfs
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
vector<int> v;
vector<bool> found;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<int>(n);
found = vector<bool>(n, false);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
queue<pair<int, int>> q;
q.push({ 0,0 });
found[0] = true;
int ans = -1;
while (!q.empty()) {
auto curr = q.front();
q.pop();
if (curr.first == v.size() - 1) {
ans = curr.second;
break;
}
for (int i = 1; i <= v[curr.first]; i++) {
int next = curr.first + i;
if (next >= v.size()) break;
if (found[next]) continue;
q.push({ next,curr.second + 1 });
found[next] = true;
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 1956번 운동 C++ (0) | 2022.11.11 |
---|---|
백준 14241번 슬라임 합치기 C++ (0) | 2022.11.09 |
백준 20311번 화학 실험 C++ (0) | 2022.11.05 |
백준 23351번 물 주기 C++ (0) | 2022.11.04 |
백준 1245번 농장 관리 C++ (0) | 2022.11.03 |