-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9019.cpp
More file actions
98 lines (91 loc) · 2.23 KB
/
9019.cpp
File metadata and controls
98 lines (91 loc) · 2.23 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 9019. DSLR
// 2020.09.06
// BFS
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
bool visit[10001];
char how[10001]; // how[next] : next로 어떤 방식을 써서 갔는지 저장
int from[10001]; // from[next] : next가 어떤 수에서 왔는지 저장
void Init()
{
for (int i = 0; i < 10001; i++)
{
visit[i] = false;
how[i] = 0;
from[i] = 0;
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
int a, b;
cin >> a >> b;
Init();
visit[a] = true;
// dist[a] = 0;
from[a] = -1;
queue<int> q;
q.push(a);
while (!q.empty())
{
int now = q.front();
q.pop();
// D : 2배 후 10000으로 나눈 나머지
int next = (now * 2) % 10000;
if (visit[next] == false)
{
q.push(next);
visit[next] = true;
from[next] = now;
how[next] = 'D';
}
// S : 1을 뺀 값. -1이면 9999로
next = now - 1;
if (next == -1)
{
next = 9999;
}
if (visit[next] == false)
{
q.push(next);
visit[next] = true;
from[next] = now;
how[next] = 'S';
}
// L : 각 자릿수를 왼편으로 회전
next = (now % 1000) * 10 + now / 1000;
if (visit[next] == false)
{
q.push(next);
visit[next] = true;
from[next] = now;
how[next] = 'L';
}
// R : 각 자릿수를 오른편으로 회전
next = (now / 10) + (now % 10) * 1000;
if (visit[next] == false)
{
q.push(next);
visit[next] = true;
from[next] = now;
how[next] = 'R';
}
}
// 답 출력
string ans = "";
while (b != a)
{
ans += how[b];
b = from[b];
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
return 0;
}