-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSLR.cpp
86 lines (80 loc) · 1.64 KB
/
DSLR.cpp
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<queue>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector<bool> check(10001);
vector<int> dist(10001);
vector<int> from(10001);
vector<char> how(10001);
int t;
cin >> t;
while (t--) {
int start, destination;
cin >> start >> destination;
fill(check.begin(), check.end(), false);
fill(dist.begin(), dist.end(), 0);
fill(dist.begin(), dist.end(), 0);
fill(how.begin(), how.end(), 0);
queue<int> data;
data.push(start);
dist[start] = 1;
while (!data.empty()) {
int now = data.front();
data.pop();
int next = (2 * now) % 10000; // function D
if (check[next] == false)
{
data.push(next);
check[next] = true;
dist[next] = dist[now] + 1;
from[next] = now;
how[next] = 'D';
}
if (now == 0)
next = 9999;
else
next = now - 1;
if (check[next] == false)
{
data.push(next);
check[next] = true;
dist[next] = dist[now] + 1;
from[next] = now;
how[next] = 'S';
}
next = (now % 1000) * 10 + (now / 1000);
if (check[next] == false)
{
data.push(next);
check[next] = true;
dist[next] = dist[now] + 1;
from[next] = now;
how[next] = 'L';
}
next = (now / 10) + (now % 10) * 1000;
if (check[next] == false)
{
data.push(next);
check[next] = true;
dist[next] = dist[now] + 1;
from[next] = now;
how[next] = 'R';
}
if (check[destination] == true)
break;
}
string ans = "";
while (destination != start)
{
ans += how[destination];
destination = from[destination];
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
return 0;
}