{"id":25,"date":"2023-01-21T18:44:00","date_gmt":"2023-01-21T10:44:00","guid":{"rendered":"https:\/\/solost.cn\/?p=25"},"modified":"2023-02-02T00:52:56","modified_gmt":"2023-02-01T16:52:56","slug":"52","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=25","title":{"rendered":"2023\u725b\u5ba2\u5bd2\u5047\u7b97\u6cd5\u57fa\u7840\u96c6\u8bad\u84253 G-\u4e25\u8083\u53e4\u677f\u7684\u79e9\u5e8f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/4194375339.png\" alt=\"\" title=\"\"><\/p>\n<p>\u8fd9\u9053\u9898\u7684\u89e3\u6cd5\u662f\u66b4\u529b\u641c\u7d22\u51fa\u53ef\u80fd\uff0c\u770b\u4e09\u79cd\u60c5\u51b5\u54ea\u79cd\u7b26\u5408\uff0cdfs,bfs\u5747\u53ef<\/p>\n<pre><code class=\"C++\">#include &lt;algorithm&gt;\n#include &lt;bitset&gt;\n#include &lt;cmath&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;map&gt;\n#include &lt;queue&gt;\n#include &lt;set&gt;\n#include &lt;stack&gt;\n#include &lt;unordered_map&gt;\n#include &lt;vector&gt;\n\nusing namespace std;\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\ntypedef long long ll;\ntypedef pair&lt;int, int&gt; PII;\ntypedef unsigned long long ull;\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\n\nll qmi(ll n, ll k, ll p)\n{\n    ll res = 1 % p;\n    n = n % p;\/\/\u6ce8\u610f\uff0c\u867d\u7136\u6bcf\u4e2a\u6570\u5b57\u90fd\u4e0d\u53ef\u80fd\u8d85\u8fc71e9\uff0c\u4f46\u662f\u7ecf\u8fc7\u7d2f\u52a0\u53ef\u80fd\u8d85\u8fc7int\u8303\u56f4\uff0c\n    while (k) {\n        if (k &amp; 1)\n            res = 1ll * res * n % p;\n        n = 1ll * n * n % p;\/\/n\u53ef\u80fd\u5728n * n\u7684\u65f6\u5019\u8d85\u8fc7ll\u8303\u56f4\uff0c\u6240\u4ee5\u9700\u8981\u5148\u53d6\u4f59\n        k &gt;&gt;= 1;\n    }\n    return res;\n}\n\nll res = 0, cnt = 0, f = 0, b[20];\nstring ans;\nstruct node {\n    ll first, second;\/\/first\u662f\u524dn\u9879\u64cd\u4f5c\u540e\u7684\u6570\u5b57\uff0csecond\u662f\u5904\u7406\u4e86\u51e0\u4e2a\u6570\u5b57\u4e86\n    string s;\/\/\u5b58\u653e\u8fdb\u884c\u7684\u64cd\u4f5c\n};\nvoid bfs()\n{\n    queue&lt;node&gt; q;\n    node head;\n    head.first = b[1];\n    head.second = 1;\n    q.push(head);\n    while (q.size()) {\n        auto t = q.front();\n        q.pop();\n        if ((int)t.s.size() &gt;= cnt)\n            continue;\n        for (int i = 0; i &lt; 3; i++) {\n            auto ne = t;\n            if (i == 0) {\n                ne.first += b[ne.second + 1];\n                ne.second++;\n                ne.s = ne.s + &#039;+&#039;;\n            } else if (i == 1) {\n                ne.first -= b[ne.second + 1];\n                ne.second++;\n                ne.s = ne.s + &#039;-&#039;;\n            } else if (i == 2) {\n                if (ne.first &lt;= 0 || b[ne.second + 1] &lt;= 0)\n                    continue;\n                ne.first = qmi(ne.first, ne.first, b[ne.second + 1]);\n                ne.second++;\n                ne.s = ne.s + &#039;#&#039;;\n            }\n            q.push(ne);\n            if ((int)ne.s.size() == cnt &amp;&amp; ne.first == b[res]) {\n                f = 1;\n                ans = ne.s;\n                return;\n            }\n        }\n    }\n}\nint main()\n{\n    ll xx;\n    string s;\n    char op = &#039;a&#039;;\n    while (cin &gt;&gt; xx) {\n        s = s + to_string(xx);\n        b[++res] = xx;\n        if (op == &#039;=&#039;)\n            break;\n        cin &gt;&gt; op;\n        s = s + op;\n        if (op == &#039;?&#039;)\n            cnt++;\n    }\n    bfs();\n    if (!f) {\n        cout &lt;&lt; &quot;-1\\n&quot;;\n    } else {\n        int j = 0;\n        for (int i = 0; i &lt; (int)s.size(); i++) {\n            if (s[i] == &#039;?&#039;) {\n                s[i] = ans[j++];\n            }\n        }\n        cout &lt;&lt; s &lt;&lt; endl;\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u9053\u9898\u7684\u89e3\u6cd5\u662f\u66b4\u529b\u641c\u7d22\u51fa\u53ef\u80fd\uff0c\u770b\u4e09\u79cd\u60c5\u51b5\u54ea\u79cd\u7b26\u5408\uff0cdfs,bfs\u5747\u53ef #include &lt;algorithm&gt; #include &lt;bitset&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;map&gt; #include &lt;queue&gt; #include &lt;set&gt; #include &lt;stack&gt; #include &lt;unordered_map&gt; #include &lt;vector&gt; using namespace std; #define endl &#039;\\n&#039; #define IOS \\ ios_base::sync_with_stdio(0); \\ cin.tie(0); \\ cout.tie(0); typedef long long ll; typedef pair&lt;int, int&gt; PII; typedef unsigned long long [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[10,8,9],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-solution","tag-10","tag-8","tag-9"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}