BOJ::11060 점프 점프

https://www.acmicpc.net/problem/11060


5014번 스타트링크, 1697 숨바꼭질 등과 매우 유사한 문제.

그치만 다른것은 역주행이 있는 반면 이 문제는 정주행밖에 없기 때문에 더 쉽다.


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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <queue>
using namespace std;
 
int n,cur,time;
int map[1001];
bool visited[1001];
 
struct Node {
    int cur;
    int time;
    Node(int c, int t) {
        cur = c;
        time = t;
    }
};
 
void bfs() {
    queue<Node> q;
    q.push(Node(1,0));
    while (!q.empty()) {
        cur = q.front().cur;
        time = q.front().time;
        q.pop();
 
        if (cur == n) {
            printf("%d\n", time);
            return;
        }
        for (int i = 1; i <= map[cur]; i++) {
            int next = cur + i;
            if (next <= n) {
                if (!visited[next]) {
                    visited[next] = true;
                    q.push(Node(next, time + 1));
                }
            }
        }
    }
    printf("-1\n");
}
 
int main() {
    scanf("%d"&n);
    for (int i = 1; i <= n; i++) {
        scanf("%d"&map[i]);
    }
    bfs();
}
cs


'BOJ::문제풀이' 카테고리의 다른 글

11403 경로 찾기  (2) 2018.01.07
11265 끝나지 않는 파티  (0) 2018.01.06
11057 오르막 수  (0) 2018.01.06
11055 가장 큰 증가 부분 수열  (0) 2018.01.06
11053 가장 긴 증가하는 부분 수열  (0) 2018.01.06

+ Recent posts