Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 정석
- 구현
- Computer science
- 알고리즘
- coding
- 코테
- bfs
- 북리뷰
- 컴퓨터공학과
- cs
- 문제풀이
- OS
- 컴공
- Stack
- 정석학술정보관
- vector
- 그래프
- 너비우선탐색
- 컴공과
- c++
- DP
- 스택
- 브루트포스
- 오퍼레이팅시스템
- 코딩
- 개발
- 백준
- Operating System
- 자료구조
- 오에스
Archives
- Today
- Total
Little Jay
[C++]백준 5014번 - 면접에 늦었다 본문
BFS 구현으로 풀 수 있는 문제
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int dist[1000001];
bool check[1000001];
int q[1000000];
int f, s, g, u, d;
/*
* bfs 조건 분기는 0 < RESULT <= F이다
*/
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> f >> s >> g >> u >> d;
int begin = 0;
int end = 0;
q[end++] = s;
dist[s] = 0;
check[s] = true;
while (begin < end) {
int now = q[begin++];
if (now + u <= f && check[now + u] == false) {
q[end++] = now + u;
dist[now + u] = dist[now] + 1;
check[now + u] = true;
}
if (now - d >= 1 && check[now - d] == false) {
q[end++] = now - d;
dist[now - d] = dist[now] + 1;
check[now - d] = true;
}
}
if (check[g] == false) {
cout << "use the stairs" << endl;
}
else {
cout << dist[g] << endl;
}
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 6679번 - 싱기한 네자리 숫자 (0) | 2022.03.20 |
---|---|
[C++] 백준 1655번 - 가운데를 말해요 (0) | 2022.03.14 |
[C++] 백준 11055번 - 가장 큰 증가 부분 수열 (0) | 2022.02.21 |
[C++] 백준 9461번 - 파도반 수열 (0) | 2022.02.21 |
[C++] 백준 1236 - 성지키기 (0) | 2022.02.19 |
Comments