Notice
Recent Posts
Recent Comments
250x250
Creative Code
[9019번]DSLR 본문
728x90
https://www.acmicpc.net/problem/9019
#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#define endl "\n"
#define MAX 10000
using namespace std;
int Start, End;
bool Visit[MAX];
void Initialize()
{
memset(Visit, false, sizeof(Visit));
}
void Input()
{
cin >> Start >> End;
}
string BFS(int a)
{
queue<pair<int, string>> Q;
Q.push(make_pair(a, ""));
Visit[a] = true;
while (Q.empty() == 0)
{
int x = Q.front().first;
string s = Q.front().second;
Q.pop();
if (x == End) return s;
int nx = x * 2;
if (nx > 9999) nx = nx % 10000;
if (Visit[nx] == false)
{
Visit[nx] = true;
Q.push(make_pair(nx, s + "D"));
}
nx = x - 1;
if (nx < 0) nx = 9999;
if (Visit[nx] == false)
{
Visit[nx] = true;
Q.push(make_pair(nx, s + "S"));
}
nx = (x % 1000) * 10 + (x / 1000);
if (Visit[nx] == false)
{
Visit[nx] = true;
Q.push(make_pair(nx, s + "L"));
}
nx = (x % 10) * 1000 + (x / 10);
if (Visit[nx] == false)
{
Visit[nx] = true;
Q.push(make_pair(nx, s + "R"));
}
}
}
void Solution()
{
string R = BFS(Start);
cout << R << endl;
}
void Solve()
{
int Tc;
cin >> Tc;
for (int T = 1; T <= Tc; T++)
{
Initialize();
Input();
Solution();
}
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("Input.txt", "r", stdin);
Solve();
return 0;
}
728x90
'백준 문제풀이' 카테고리의 다른 글
[9935번]문자열 폭발 (0) | 2023.09.24 |
---|---|
[9663번]N-Queen (0) | 2023.09.24 |
[7662번]이중 우선순위 큐 (0) | 2023.09.24 |
[1806번]부분합 (0) | 2023.09.24 |
[1753번]최단경로 (0) | 2023.09.24 |