Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 10026번
- 윤성우 저자
- Four Squares
- OS
- redis
- 열혈 tcp/ip 프로그래밍
- 제프리리처
- 우아한레디스
- 열혈 TCP/IP 소켓 프로그래밍
- 토마토
- C#
- Operating System.
- 우아한 테크 세미나
- 운영체제
- n타일링2
- 스프링 입문
- C++
- HTTP
- BOJ
- Operating System
- 2475번
- Spring
- 이펙티브코틀린
- inflearn
- 에러핸들링
- 스프링 핵심 원리
- 김영한
- TCP/IP
- FIFO paging
- Window-Via-c/c++
Archives
- Today
- Total
나의 브을로오그으
[c++] 9019번 : DSLR 본문
https://www.acmicpc.net/problem/9019
#include <iostream>
#include <queue>
#include <string>
using namespace std;
string Progress(int n, int ans)
{
bool visited[10000] = { false, };
queue<pair<int, string>> q;
q.emplace(n, "");
visited[n] = true;
while (q.empty() == false)
{
int cur = q.front().first;
string cmd = q.front().second;
q.pop();
if (cur == ans)
{
return cmd;
}
int D, S, L, R;
D = cur * 2 % 10000;
S = cur - 1 < 0 ? 9999 : cur - 1;
L = cur % 1000 * 10 + cur / 1000;
R = cur % 10 * 1000 + cur / 10;
if (visited[D] == false)
{
visited[D] = true;
q.emplace(D, cmd + "D");
}
if (visited[S] == false)
{
visited[S] = true;
q.emplace(S, cmd + "S");
}
if (visited[L] == false)
{
visited[L] = true;
q.emplace(L, cmd + "L");
}
if (visited[R] == false)
{
visited[R] = true;
q.emplace(R, cmd + "R");
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
vector<int> cmdLine;
int T, n, ans;
cin >> T;
for (int i = 0; i < T; ++i)
{
cin >> n >> ans;
string cmdLine = Progress(n, ans);
cout << cmdLine << '\n';
}
return 0;
}
'알고리즘 > BaekJoon' 카테고리의 다른 글
[c++] 10026번 : 적록색약 (0) | 2022.11.16 |
---|---|
[c++] 7662번 : 이중 우선순위 큐 (0) | 2022.10.26 |
[c++] 7576번 : 토마토 (0) | 2022.10.21 |
[c++] 7569번 : 토마토 (0) | 2022.10.19 |
[c++] 18870번 : 좌표 압축 (0) | 2022.10.12 |