일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 스위핑 알고리즘
- ROP
- 백트래킹
- 투 포인터
- House of Orange
- heap
- 다이나믹 프로그래밍
- 연결리스트
- 이진트리
- off by one
- 분할 정복
- 포맷스트링버그
- RTL
- 브루트 포스
- syscall
- BFS
- 동적 계획법
- BOF
- 이진 탐색
- 이분 탐색
- 문자열 처리
- OOB
- 스택
- 수학
- 완전 탐색
- fsb
- tcache
- DFS
- 큐
- 에라토스테네스의 체
Archives
- Today
- Total
SDJ( 수돈재 아님 ㅎ )
[C++] 5014 - 스타트링크 본문
문제 링크 : https://www.acmicpc.net/problem/5014
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<int, int> 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