-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9019.cpp
More file actions
86 lines (80 loc) · 1.67 KB
/
9019.cpp
File metadata and controls
86 lines (80 loc) · 1.67 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <memory.h>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
pair<int,int> visited[10001];
stack<char> st;
queue<int> op;
queue<int> q;
int A,B;
void bfs(int a){
visited[a]={-1,a};
q.push(a);
while(!q.empty()){
int u=q.front();
q.pop();
if(u==B) break;
int n;
for(int i=1;i<=4;i++){
switch(i){
case 1:
n=2*u%10000;
break;
case 2:
n=(u+9999)%10000;
break;
case 3:
n=(u%1000)*10+u/1000;
break;
case 4:
n=u/10+(u%10)*1000;
break;
}
if(visited[n].first==0){
visited[n]={i,u};
q.push(n);
}
}
}
}
void tracing(int cur){
if(visited[cur].first==-1) return;
switch(visited[cur].first){
case 1:
st.push('D');
break;
case 2:
st.push('S');
break;
case 3:
st.push('L');
break;
case 4:
st.push('R');
break;
}
tracing(visited[cur].second);
}
int main()
{
io;
int T;
cin>>T;
for(int t=0;t<T;t++){
memset(visited,'\0',sizeof(visited));
while(!q.empty()) q.pop();
cin>>A>>B;
bfs(A);
tracing(B);
while(!st.empty()){
cout<<st.top();
st.pop();
}
cout<<'\n';
}
return 0;
}