728x90
๋ฌธ์ ์ ํ์ด ๊ฐ๊ณ ์๋ฅ ์ํ ๋ฌธ์ ํ๋์์ญ ์ ๋ฆฌํ๋ ๊ธฐ๋ถ์ด๋ค.
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define MAX 1000010
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int F, S, G, U, D;
queue<int> q;
vector<int> visited(MAX, 0);
vector<int> path(MAX, 0);
cin >> F >> S >> G >> U >> D;
q.push(S);
visited[S] = 1;
int count = 0;
while(!q.empty()) {
int node = q.front();
q.pop();
if(node == G) {
cout << path[G] << endl;
return 0;
}
if(node + U <= F && visited[node + U] == 0) {
visited[node + U] = 1;
q.push(node+U);
path[node + U] = path[node] + 1;
}
if(node - D >= 1 && visited[node - D] == 0 ) {
visited[node - D] = 1;
q.push(node-D);
path[node-D] = path[node] + 1;
}
}
cout << "use the stairs" << endl;
return 0;
}
'๐ Self Study > ๐ BaekJoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค BaekJoon (์์ ์์ญ, 2468๋ฒ) C++ (0) | 2022.01.12 |
---|---|
๋ฐฑ์ค BaekJoon (์คํํธ๋งํฌ, 5014๋ฒ) C++ (0) | 2022.01.11 |
๋ฐฑ์ค BaekJoon (์จ๋ฐ๊ผญ์ง, 1697๋ฒ) C++ (0) | 2022.01.11 |
๋ฐฑ์ค BaekJoon (ํ ๋งํ , 7569๋ฒ) C++ (0) | 2022.01.11 |
๋ฐฑ์ค BaekJoon(์ด์ ๊ณ์ฐ, 2644๋ฒ) C++ (0) | 2022.01.10 |