首页
社区
课程
招聘
[原创]第二题
2021-5-13 11:40 1792

[原创]第二题

2021-5-13 11:40
1792

一道新奇的迷宫题,能侧着走,区别是行数奇偶的时候方向受限制。
首先手动算出路线,然后爆破一遍符合路线的输入即可。

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
#include <iostream>
 
std::wstring get_path(int value, int &yp) {
    std::wstring ret;
    switch (value) {
        default:
            ret = ((yp & 1) == 0) ? L"↗" : L"↑";
            yp--;
            break;
        case 1:
            ret = L"→";
            break;
        case 2:
            ret = ((yp & 1) == 0) ? L"↘" : L"↓";
            yp++;
            break;
        case 3:
            ret = ((yp & 1) == 0) ? L"↓" : L"↙";
            yp++;
            break;
        case 4:
            ret = L"←";
            break;
        case 5:
            ret = ((yp & 1) == 0) ? L"↑" : L"↖";
            yp--;
            break;
    }
    return ret;
}
 
int main() {
    std::wstring path = L"→↘↙←↓↓→↘↙←↓↓→→↗→↓→↗↑↑↑↑←↙←↑↑↑↑→↘→↑→↘→↓↓←↙↘↓↓↓→";
    std::string char_table = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
    std::wcout << path << std::endl;
    std::string answer = "";
 
    int y_ptr = 0;
    int path_ptr = 0;
    for (int input_ptr = 0; input_ptr < 24; ++input_ptr) {
        for (int table_ptr = 0; table_ptr < 36; ++table_ptr) {
            int yp = y_ptr;
            int a1 = 5 - (table_ptr + input_ptr) % 6;
            int a2 = (input_ptr + table_ptr / 6) % 6;
            std::wstring c = get_path(a1, yp);
            c += get_path(a2, yp);
            auto cmp = path.substr(path_ptr, 2);
            if (cmp == c) {
                answer += char_table.substr(table_ptr, 1);
                std::wcout << c;
                path_ptr += 2;
                y_ptr = yp;
                break;
            }
        }
    }
    std::cout << answer << std::endl;
 
    return 0;
}

[培训]《安卓高级研修班(网课)》月薪三万计划

收藏
点赞0
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回