-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaekJoon5014.cpp
More file actions
39 lines (35 loc) · 787 Bytes
/
BaekJoon5014.cpp
File metadata and controls
39 lines (35 loc) · 787 Bytes
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
//BaekJoon 5014 스타트링크
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int f, s, g, u, d; cin >> f >> s >> g >> u >> d;
bool visited[1000001] = { false };
queue<pair<int, int>> qu;
qu.push(make_pair(s, 0));
visited[s] = true;
while (!qu.empty()) {
int point = qu.front().first;
int num = qu.front().second;
qu.pop();
if (point == g) {
cout << num;
return 0;
}
int up = point + u;
int down = point - d;
if (up <= f && visited[up] == false) {
qu.push(make_pair(up, num + 1));
visited[up] = true;
}
if (down > 0 && visited[down] == false) {
qu.push(make_pair(down, num + 1));
visited[down] = true;
}
}
cout << "use the stairs";
return 0;
}