C++
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
struct Q_info{
int n;
};
queue<Q_info> q;
int N;
char result[10010][10010];
int check[10010];
int memory[10010][2];
void ClearQueue(queue<Q_info> &someQueue)
{
queue<Q_info> empty_;
swap(someQueue, empty_);
}
void reverseString(char* s) {
size_t size_ = strlen(s);
char temp;
for (size_t i = 0; i < size_ / 2; i++) {
temp = s[i];
s[i] = s[(size_ - 1) - i];
s[(size_ - 1) - i] = temp;
}
}
int main()
{
scanf("%d",&N);
for(int i=0;i<N;i++){
int f,b;
scanf("%d %d",&f,&b);
ClearQueue(q);
memset(check,0,sizeof(check));
memset(memory,0,sizeof(memory));
q.push({f});
check[f]=1;
while(!q.empty()){
Q_info a=q.front();
q.pop();
if(a.n==b){
//result[i]=a.path;
break;
}
if(check[(a.n*2)%10000]==0){
check[(a.n*2)%10000]=1;
q.push({(a.n*2)%10000});//1==d
memory[(a.n*2)%10000][0]=a.n;
memory[(a.n*2)%10000][1]=1;
}
if(a.n==0){
if(check[9999]==0){
check[9999]=1;
q.push({9999});
memory[9999][0]=a.n;
memory[9999][1]=2;
}
}else{
if(check[a.n-1]==0){
check[a.n-1]=1;
q.push({a.n-1});
memory[a.n-1][0]=a.n;
memory[a.n-1][1]=2;
}
}
int num=a.n%10;
if(check[a.n/10+num*1000]==0){
check[a.n/10+num*1000]=1;
q.push({a.n/10+num*1000});
memory[a.n/10+num*1000][0]=a.n;
memory[a.n/10+num*1000][1]=4;
}
num=a.n/1000;
if(check[a.n%1000*10+num]==0){
check[a.n%1000*10+num]=1;
q.push({a.n%1000*10+num});
memory[a.n%1000*10+num][0]=a.n;
memory[a.n%1000*10+num][1]=3;
}
}
int idx=b;
int idx_s=0;
while(1){
if(memory[idx][1]==0){
break;
}
switch(memory[idx][1]){
case 1:
result[i][idx_s]='D';
break;
case 2:
result[i][idx_s]='S';
break;
case 3:
result[i][idx_s]='L';
break;
case 4:
result[i][idx_s]='R';
break;
}
idx_s++;
idx=memory[idx][0];
}
}
for(int i=0;i<N;i++){
reverseString(result[i]);
printf("%s\n",result[i]);
}
return 0;
}
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
공지 | 안내사항 | 관리자 | 2019.12.21 | 163 |
74 | 9663 | 관리자 | 2019.12.21 | 114 |
73 | 9345 | 관리자 | 2020.04.11 | 150 |
» | 9019 | 관리자 | 2019.12.21 | 113 |
71 | 7569 | 관리자 | 2019.12.21 | 113 |
70 | 6987 | 관리자 | 2019.12.21 | 113 |
69 | 5842 | 관리자 | 2020.04.11 | 151 |
68 | 5625 | 관리자 | 2019.12.21 | 109 |
67 | 5419 | 관리자 | 2020.04.11 | 155 |
66 | 3392 | 관리자 | 2020.04.11 | 156 |
65 | 3019 | 관리자 | 2019.12.21 | 111 |
64 | 2933 | 관리자 | 2019.12.21 | 112 |
63 | 2931 | 관리자 | 2019.12.21 | 111 |
62 | 2836 | 관리자 | 2019.12.21 | 110 |
61 | 2667 | 관리자 | 2019.12.21 | 113 |
60 | 2636 | 관리자 | 2019.12.21 | 113 |
59 | 2629 | 관리자 | 2020.04.11 | 146 |
58 | 2615 | 관리자 | 2019.12.21 | 111 |
57 | 2610 | 관리자 | 2020.04.11 | 146 |
56 | 2606 | 관리자 | 2019.12.21 | 111 |
55 | 2585 | 관리자 | 2019.12.21 | 113 |
54 | 2578 | 관리자 | 2019.12.21 | 111 |
53 | 2573 | 관리자 | 2020.04.11 | 151 |
52 | 2557 | 관리자 | 2019.12.21 | 111 |
51 | 2512 | 관리자 | 2019.12.21 | 111 |
50 | 2504 | 관리자 | 2020.04.11 | 147 |
49 | 2481 | 관리자 | 2019.12.21 | 112 |
48 | 2478 | 관리자 | 2020.04.11 | 148 |
47 | 2473 | 관리자 | 2020.04.11 | 153 |
46 | 2470 | 관리자 | 2020.04.11 | 151 |