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
87
88
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
queue<pair<intstring>> dongdong;
int ca, allsize;
int q, aw, start;
int checked[10000= { 0, };
int temp;
int qsize;
void cal(int a, int b) {
    if (dongdong.front().first == aw) {
        cout << dongdong.front().second << endl;
        qsize = 0;
        queue < pair<intstring> >emptyq;
        swap(dongdong, emptyq);
        memset(checked, 0sizeof(checked));
    }
    if (a != b) {
 
        if (a * 2 >= 10000) {
            start = a * 2 % 10000;
            if (checked[start] != 1) {
                dongdong.push(make_pair(start, dongdong.front().second + "D"));
                checked[start] = 1;
            }
        }
        else {
            start = a * 2;
            if (checked[start] != 1) {
                dongdong.push(make_pair(start, dongdong.front().second + "D"));
                checked[start] = 1;
            }
 
        }
        if (a == 0) {
            start = 9999;
            if (checked[start] != 1) {
                dongdong.push(make_pair(start, dongdong.front().second + "S"));
                checked[start] = 1;
            }
 
        }
        else {
            start = a - 1;
            if (checked[start] != 1) {
                dongdong.push(make_pair(start, dongdong.front().second + "S"));
                checked[start] = 1;
            }
        }
        start = a * 10 % 10000 + a / 1000;
        if (checked[start] != 1) {
            dongdong.push(make_pair(start, dongdong.front().second + "L"));
            checked[start] = 1;
        }
        start = a % 10 * 1000 + a / 10;
        if (checked[start] != 1) {
            dongdong.push(make_pair(start, dongdong.front().second + "R"));
            checked[start] = 1;
        }
    }
}
int main() {
    //freopen("test.txt", "r", stdin);
    cin >> ca;
 
 
    for (int k = 0; k < ca; k++) {
        cin >> q >> aw;
 
        dongdong.push(make_pair(q, ""));
 
        while (!dongdong.empty()) {
            qsize = dongdong.size();
 
            for (int i = 0; i < qsize; i++) {
                cal(dongdong.front().first, aw);
                if (!dongdong.empty())dongdong.pop();
            }
 
        }
    }
 
}
 
cs


DSLR 다시풀어봐도 몇번 틀리고 ..

'재미있는공부이야기 > 알고리듬' 카테고리의 다른 글

백준 17071번 숨바꼭질 5  (0) 2019.03.21
백준 14499번 주사위굴리기  (0) 2019.02.28
백준 7569번 토마토  (0) 2019.02.20
백준 2178번 미로찾기  (0) 2019.02.20
KMP 알고리즘  (0) 2019.02.15

+ Recent posts