https://www.acmicpc.net/problem/5014
나는 바보다
두 가지를 모두 처리해야하는데
if else if문으로 분기 처리했다
나는 바보인게 확실하다
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <limits.h>
#include <queue>
#include <set>
#include <math.h>
#include <stack>
#include <deque>
using namespace std;
int visited[2000001] = { 0 };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int f, s, g, u, d;
queue<int> q;
cin >> f >> s >> g >> u >> d;
q.push(s);
visited[s] = 1;
while (!q.empty()) {
int x = q.front();
q.pop();
if (x == g) {
cout << visited[x] -1;
return 0;
}
if (x + u <= f && !visited[x + u] && u > 0) {
q.push(x + u);
visited[x + u] = visited[x] + 1;
}
if (x - d >= 1 && !visited[x - d] && d > 0) {
q.push(x - d);
visited[x - d] = visited[x] + 1;
}
}
cout << "use the stairs";
return 0;
}
'PS > BOJ' 카테고리의 다른 글
[백준] 7569. 토마토(c++) (0) | 2025.03.02 |
---|---|
[백준] 10026. 적록색약(c++) (0) | 2025.03.02 |
[백준]1012. 유기농배추(c++) (0) | 2025.02.24 |
[백준] 1697. 숨바꼭질(c++) (0) | 2025.02.24 |
[백준] 4179. 불!(c++) (0) | 2025.02.24 |