백준
C++ 5014 스타트링크
안선생
2023. 2. 26. 16:11
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
|
#include <iostream>
#include <vector>
#include<queue>
using namespace std;
bool visit[1000001] = { 0 };
int f, s, g, u, d;
int cnt = 0;
void bfs(int x)
{
queue <pair<int, int>> a;
a.push({ x,0 });
visit[x] = 1;
while (!a.empty())
{
int xx = a.front().first;
cnt = a.front().second;
if (xx == g)
{
cout << cnt;
return;
}
a.pop();
if ( xx + u <= f&&!visit[xx + u])
{
visit[xx + u] = 1;
a.push({ xx + u,cnt + 1 });
}
if (xx - d > 0 && !visit[xx - d])
{
visit[xx - d] = 1;
a.push({ xx - d,cnt + 1 });
}
}
cout << "use the stairs";
return;
}
int main()
{
cin >> f >> s >> g >> u >> d;
bfs(s);
return 0;
}
|
cs |
https://www.acmicpc.net/problem/5014
5014번: 스타트링크
첫째 줄에 F, S, G, U, D가 주어진다. (1 ≤ S, G ≤ F ≤ 1000000, 0 ≤ U, D ≤ 1000000) 건물은 1층부터 시작하고, 가장 높은 층은 F층이다.
www.acmicpc.net