{"id":1297,"date":"2024-12-07T09:00:00","date_gmt":"2024-12-07T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1297"},"modified":"2024-12-08T00:19:58","modified_gmt":"2024-12-07T16:19:58","slug":"zerojudge-d432","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-d432\/","title":{"rendered":"ZeroJudge D432: Secret Code (Pwd)"},"content":{"rendered":"\n\n\n<p>\u300c\u8cc7\u8a0a\u793e\u300d\u767c\u5c55\u4e86\u4e00\u500b\u7368\u7279\u7684\u9032\u5165\u793e\u5718\u6642\u6240\u7528\u7684\u901a\u95dc\u5bc6\u8a9e\uff0c\u70ba\u4e86\u4fdd\u5bc6\u8d77\u898b\u6bcf\u5929\u90fd<br>\u6703\u6709\u4e0d\u540c\u7684\u901a\u95dc\u5bc6\u8a9e\u3002\u901a\u95dc\u5bc6\u8a9e\u662f\u7531\u4e00\u4e32\u4e0d\u540c\u7684\u5927\u5c0f\u5beb\u82f1\u6587\u5b57\u6bcd\u53ca\uff10\u5230\uff19\u7684\u6578\u5b57<br>\u5b57\u5143\u6240\u7d44\u6210\uff0c\u4e14\u5176\u9577\u5ea6\u6700\u591a\u70ba\uff16\uff10\u500b\u5b57\u5143\uff0c\u5927\u5c0f\u5beb\u82f1\u6587\u5b57\u5143\u8996\u70ba\u4e0d\u540c\u3002\u793e\u9577\u6bcf\u5929<br>\u5c07\u8a72\u5929\u7684\u5bc6\u8a9e\u653e\u7f6e\u65bc\u53ef\u4ee5\u7531\u524d\u5e8f\u5de1\u884c (pre-order traversal) \u7522\u751f\u8a72\u5bc6\u8a9e\u7684\u4e8c\u5143\u6a39<br>\u5167\u3002\u4e14\u5c07\u4e2d\u5e8f\u5de1\u884c (in-order traversal) \u53ca\u5f8c\u5e8f\u5de1\u884c (post-order traversal) \u6240\u5f97\u7684\u5b57<br>\u4e32\u50b3\u9001\u7d66\u6240\u6709\u7684\u793e\u54e1\u3002\u8acb\u4f60\u5beb\u4e00\u500b\u7a0b\u5f0f\uff0c\u7d66\u5b9a\u67d0\u4e00\u5929\u6240\u6536\u5230\u7684\u4e2d\u5e8f\u5de1\u884c\u53ca\u5f8c\u5e8f\u5de1<br>\u884c\u5b57\u4e32\uff0c\u8acb\u89e3\u51fa\u8a72\u5929\u7684\u901a\u95dc\u5bc6\u8a9e\u3002\u4e8c\u5143\u6a39\u5de1\u884c\u65b9\u5f0f\u7bc4\u4f8b\u5982\u4e0b\u6240\u793a\uff1a<br>\u7d66\u5b9a\u4e00\u500b\u4e8c\u5143\u6a39\uff0c\u4e2d\u5e8f\u5de1\u884c\u65b9\u5f0f\u70ba\u5728\u4efb\u4e00\u9802\u9ede\u6642 (root) \u5148\u8f38\u51fa\u5de6\u908a\u5b50\u6a39\u6240\u6709\u5b57<br>\u5143\uff0c\u518d\u8f38\u51fa\u8a72\u9802\u9ede\u7684\u5b57\u5143\uff0c\u6700\u5f8c\u8f38\u51fa\u53f3\u908a\u5b50\u6a39\u6240\u6709\u5b57\u5143\u3002\u6bcf\u4e00\u500b\u5b50\u6a39\u5b57\u5143\u8f38\u51fa\u65b9<br>\u5f0f\u4e5f\u5982\u4e0a\u6240\u8ff0\u3002\u524d\u5e8f\u5de1\u884c\u65b9\u5f0f\u5247\u5728\u4efb\u4e00\u9802\u9ede\u6642 (root) \u5148\u8f38\u51fa\u9802\u9ede\u7684\u5b57\u5143\uff0c\u518d\u8f38<br>\u51fa\u5de6\u908a\u5b50\u6a39\u6240\u6709\u5b57\u5143\uff0c\u6700\u5f8c\u8f38\u51fa\u53f3\u908a\u5b50\u6a39\u6240\u6709\u5b57\u5143\u3002\u800c\u5f8c\u5e8f\u5de1\u884c\u65b9\u5f0f\u5247\u5728\u4efb\u4e00\u9802<br>\u9ede\u6642 (root) \u5148\u8f38\u51fa\u5de6\u908a\u5b50\u6a39\u6240\u6709\u5b57\u5143\uff0c\u518d\u8f38\u51fa\u53f3\u908a\u5b50\u6a39\u6240\u6709\u5b57\u5143\uff0c\u6700\u5f8c\u8f38\u51fa\u9802<br>\u9ede\u7684\u5b57\u5143\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u5176\u5167\u5bb9\u6709\u5169\u884c\u5b57\u4e32\u3002\u7b2c\u4e00\u884c\u5b57\u4e32\u662f\u4e2d\u5e8f\u5de1\u884c\u6240\u5f97\u7684\u5b57<br>\u4e32\uff0c\u7b2c\u4e00\u884c\u5b57\u4e32\u5247\u662f\u5f8c\u5e8f\u5de1\u884c\u6240\u5f97\u7684\u5b57\u4e32\u3002<\/td><td>\u8acb\u8f38\u51fa\u4e00\u884c\u7684\u901a\u95dc\u5bc6\u8a9e\u81f3\u8f38\u51fa\u6a94<\/td><\/tr><tr><td>1xB2Ay3C4z<br>x12By3z4CA<\/td><td>AB1x2C3y4z<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528\u4e2d\u5e8f\u548c\u5f8c\u5e8f\u4f86\u6c42\u524d\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528\u905e\u56de\u4f86\u5207\u5b57\u4e32\uff0c\u6bcf\u6b21\u9032\u5165\u905e\u8ff4\u7684\u6642\u5019\u90fd\u8f38\u5165\u76ee\u524d\u4e2d\u5e8f\u7684\u7b2c\u4e00\u500b\u5b57\u5143\uff0c\u4e5f\u5c31\u662f\u6839\u3002\u7136\u5f8c\u518d\u547c\u53eb\u5de6\u53f3\u5169\u908a\u7684\u51fd\u5f0f\uff0c\u53ef\u4ee5\u53c3\u8003 <a href=\"https:\/\/seanxd.com\/zerojudge-c126\/\" target=\"_blank\" rel=\"noreferrer noopener\">C126<\/a> \u7684\u89e3\u984c\u601d\u8def\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=d432\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge D432: \u901a\u95dc\u5bc6\u8a9e (pwd)<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nvoid find(const string middle, const string back) {\n    const char root = back[back.length()-1];\n    cout &lt;&lt; root;\n    for (int i = 0; i&lt;middle.length(); i++) {\n        if (middle[i] == root) {\n            if (i != 0) {\n                find(middle.substr(0, i), back.substr(0, i));\n            }\n            if (i != middle.length()-1) {\n                find(middle.substr(i+1, middle.length()-i-1), back.substr(i, back.length()-i-1));\n            }\n        }\n    }\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    string middle, back;\n    while (cin &gt;&gt; middle &gt;&gt; back) {\n        find (middle, back);\n        cout &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge D432\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u8cc7\u8a0a\u793e\u300d\u767c\u5c55\u4e86\u4e00\u500b\u7368\u7279\u7684\u9032\u5165\u793e\u5718\u6642\u6240\u7528\u7684\u901a\u95dc\u5bc6\u8a9e\uff0c\u70ba\u4e86\u4fdd\u5bc6\u8d77\u898b\u6bcf\u5929\u90fd\u6703\u6709\u4e0d\u540c\u7684\u901a\u95dc\u5bc6\u8a9e\u3002\u901a\u95dc\u5bc6\u8a9e\u662f\u7531\u4e00\u4e32\u4e0d\u540c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[29],"tags":[53,8,11,9,28],"class_list":["post-1297","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-53","tag-8","tag-11","tag-9","tag-28"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=1297"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1297\/revisions"}],"predecessor-version":[{"id":1310,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1297\/revisions\/1310"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}