SDJ( 수돈재 아님 ㅎ )

[C++] 5014 - 스타트링크 본문

알고리즘/Backjoon

[C++] 5014 - 스타트링크

ShinDongJun 2020. 1. 29. 09:26

문제 링크 : https://www.acmicpc.net/problem/5014

 

5014번: 스타트링크

문제 강호는 코딩 교육을 하는 스타트업 스타트링크에 지원했다. 오늘은 강호의 면접날이다. 하지만, 늦잠을 잔 강호는 스타트링크가 있는 건물에 늦게 도착하고 말았다. 스타트링크는 총 F층으로 이루어진 고층 건물에 사무실이 있고, 스타트링크가 있는 곳의 위치는 G층이다. 강호가 지금 있는 곳은 S층이고, 이제 엘리베이터를 타고 G층으로 이동하려고 한다. 보통 엘리베이터에는 어떤 층으로 이동할 수 있는 버튼이 있지만, 강호가 탄 엘리베이터는 버튼이 2개밖에 없

www.acmicpc.net

 

 

 

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
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
 
#define endl '\n'
 
using namespace std;
 
typedef pair<intint> pii;
 
int building[1000005];
int F;
int S, G;
int U, D;
 
void BFS()
{
    pii p;
    queue<pii> Q;
    building[S] = 1;
    Q.push(pii(S, 1));
 
    int current_floor;
    int time;
 
    while(!Q.empty())
    {
        if(building[G])
            return;
        p = Q.front(); Q.pop();
        current_floor = p.first;
        time = p.second;
 
        if(current_floor + U <= F && building[current_floor + U] == 0)
        {
            building[current_floor + U] = time+1;
            Q.push(pii(current_floor+U, time+1));
        }
        if(1 <= current_floor - D && building[current_floor - D] == 0)
        {
            building[current_floor - D] = time+1;
            Q.push(pii(current_floor-D, time+1));
        }
    }
 
}
 
int main()
{
    cin >> F >> S >> G >> U >> D;
 
    BFS();
 
    if(building[G])
        cout << building[G]-1 << endl;
    else
        cout << "use the stairs" << endl;
    return 0;
}

'알고리즘 > Backjoon' 카테고리의 다른 글

[C++] 16953 - A → B  (0) 2020.01.29
[C++] 17425 - 약수의 합  (0) 2020.01.29
[C++] 12852 - 1로 만들기 2  (0) 2020.01.29
[C++] 14502 - 연구소  (0) 2020.01.29
[C++] 10750 - Censoring  (0) 2020.01.23
Comments