-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5014.cpp
More file actions
40 lines (34 loc) · 702 Bytes
/
5014.cpp
File metadata and controls
40 lines (34 loc) · 702 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
40
#include <iostream>
#include <queue>
#include <cmath>
#define MAX 1000001
using namespace std;
int visited[1000001];
queue<int> q;
int F,S,G,U,D;
int B[2];
void BFS(){
q.push(S);
visited[S]=1;
while(!q.empty()){
int v = q.front();
q.pop();
for(int i=0; i<2; i++){
int vb = v+B[i];
if (vb<=F&&vb>0){
if (visited[vb]==0){
q.push(vb);
visited[vb] = visited[v]+1;
}
}
}
}
}
int main(){
cin >>F>>S>>G>>U>>D;
B[0]=U;
B[1]=-1*D;
BFS();
if (visited[G]==0) cout << "use the stairs";
else cout << visited[G] - 1;
}