-
[알고리즘] 9019번: DSLR - C++알고리즘/백준 2020. 12. 12. 21:42728x90
#include <iostream> #include <queue> #include <string> using namespace std; int main() { int T; cin >> T; while (T--) { int A, B, now, next; cin >> A >> B; bool check[10000] = { false, }; char how[10000] = { '\0', }; int from[10000] = { 0, }; queue<int> reg; reg.push(A); check[A] = true; while (!reg.empty()) { now = reg.front(); reg.pop(); next = (now * 2) % 10000; if (check[next] == false) { reg.push(next); check[next] = true; how[next] = 'D'; from[next] = now; } if (now == 0) next = 9999; else next = now - 1; if (check[next] == false) { reg.push(next); check[next] = true; how[next] = 'S'; from[next] = now; } next = (now % 1000) * 10 + (now / 1000); if (check[next] == false) { reg.push(next); check[next] = true; how[next] = 'L'; from[next] = now; } next = (now % 10) * 1000 + (now / 10); if (check[next] == false) { reg.push(next); check[next] = true; how[next] = 'R'; from[next] = now; } } string ans = ""; while (A != B) { ans += how[B]; B = from[B]; } reverse(ans.begin(), ans.end()); cout << ans << endl; } }
github.com/waves123/1963/blob/master/1963/9019.cpp
728x90'알고리즘 > 백준' 카테고리의 다른 글
[알고리즘] 백준 2580번: 스도쿠 - C++ (0) 2020.12.12 [알고리즘] 백준 9663번: N-Queen - C++ (0) 2020.12.12 [알고리즘] 백준 10971번: 외판원 순회 2 - C++ (0) 2020.12.12 [알고리즘] 백준 10819번: 차이를 최대로 - C++ (0) 2020.12.12 [알고리즘] 백준 1476번 : 날짜 계산 - C++ (0) 2020.12.12