{"id":283,"date":"2024-04-27T11:58:35","date_gmt":"2024-04-27T03:58:35","guid":{"rendered":"https:\/\/seanxd.com\/?p=283"},"modified":"2024-04-27T11:58:37","modified_gmt":"2024-04-27T03:58:37","slug":"zerojudge-a524","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a524\/","title":{"rendered":"ZeroJudge A524: Phone Mystery"},"content":{"rendered":"\n\n\n<p class=\"\">\u912d\u5b78\u9577\u7684\u624b\u6a5f\u88e1\u6709\u4e0d\u53ef\u544a\u4eba\u7684\u79d8\u5bc6\uff0c\u70ba\u4e86\u4e0d\u88ab\u767c\u73fe\u90a3\u4e9b\u7167\u7247\u548c\u7c21\u8a0a\uff0c\u4ed6\u5c0f\u5fc3\u7ffc\u7ffc\u5730\u628a\u624b\u6a5f\u4e0a\u9396\u4e86\u3002<br>\u5e78\u597d\uff0c\u4f60\u662f\u500b\u6703\u5beb\u7a0b\u5f0f\u7684\u5929\u624d\uff0c\u4f60\u80fd\u5920<strong>\u7522\u751f\u6240\u6709\u7684\u5bc6\u78bc\u53bb\u5617\u8a66<\/strong>\uff0c\u73fe\u5728\u8d95\u5feb\u52d5\u624b\u5427\uff01<br>\u5662\uff01\u9084\u6709\u4e00\u4ef6\u4e8b\uff0c\u57fa\u65bc\u67d0\u4e9b\u7406\u7531\uff0c\u4f60\u77e5\u9053\u912d\u5b78\u9577\u7684<strong>\u5bc6\u78bc\u6c92\u6709\u91cd\u8986\u7684\u5b57<\/strong>\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 nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td><strong>EOF<\/strong> \u8f38\u5165\uff0c\u6bcf\u7b46\u8cc7\u6599\u6709\u4e00\u500b N (N &lt;= 8)\uff0c\u4ee3\u8868\u912d\u5b78\u9577\u7684\u5bc6\u78bc\u4f4d\u6578\u3002<\/td><td>\u8f38\u51fa\u6240\u6709\u53ef\u80fd\u7684\u5bc6\u78bc\uff0c<strong>\u4f9d\u5b57\u5178\u9806\u5e8f\u53cd\u5411\u6392\u5217<\/strong> (\u56e0\u70ba\u4f60\u89ba\u5f97\u4ed6\u7684\u5bc6\u78bc\u61c9\u8a72\u5728\u5f8c\u534a\u6bb5\uff09\u3002<\/td><\/tr><tr><td>3<br>2<\/td><td>321<br>312<br>231<br>213<br>132<br>123<br>21<br>12<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u4f7f\u7528<strong>\u905e\u8ff4<\/strong>\u5c07<strong>\u6bcf\u4e00\u7a2e\u6578\u5b57\u52a0\u5230\u5b57\u4e32<\/strong>\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f<strong>\u4e0d\u80fd\u6709\u91cd\u8907\u7684\u6578\u5b57<\/strong>\uff0c\u53ef\u4ee5\u4f7f\u7528 <strong>Map<\/strong> \u6216 <strong>Set<\/strong> \u4f86\u505a\u5224\u65b7\u3002\u7576\u5224\u65b7\u5230\u5b57\u4e32\u9577\u5ea6\u70ba N \u6642\uff0c\u5c07\u5b57\u4e32\u8f49\u70ba\u6574\u6578\u4e26\u5b58\u5230\u4e00\u500b\u9663\u5217\u4e2d\uff0c\u4e00\u6a23<strong>\u8981\u5148\u5224\u65b7\u662f\u5426\u5df2\u7d93\u6709\u5b58\u904e\u4e00\u6a23\u7684\u6578\u5b57<\/strong>\u4e86\u3002\u6700\u5f8c\u4f7f\u7528 <strong>Sort<\/strong> \u6392\u5e8f\u9663\u5217\u4e4b\u5f8c\u5f9e<strong>\u6700\u5f8c\u4e00\u9805\u5f80\u524d\u8f38\u51fa<\/strong>\u5373\u53ef\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a524\" target=\"_blank\" rel=\"noopener\">ZeroJudge A524: \u624b\u6a5f\u4e4b\u8b0e<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;map&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nint N;\nvector&lt;int&gt;ans;\nmap&lt;int, int&gt;MAP;\n\nvoid hi(string str, map&lt;int, int&gt;exist)\n{\n    if (str.length() == N)\n    {\n        int tmp;\n        if (str.length() == 1) tmp = int(str[0] - &#39;0&#39;);\n        else tmp = stoi(str);\n        if (MAP[tmp] == 0)\n        {\n            ans.push_back(tmp);\n            MAP[tmp]++;\n            return;\n        }\n    }\n    for (int i = 1; i&lt;=N; i++)\n    {\n        if (exist[i] == 0)\n        {\n            exist[i]++;\n            hi(str+to_string(i), exist);\n            exist[i]--;\n        }\n    }\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    while (cin &gt;&gt; N)\n    {\n        string str = &quot;&quot;;\n        map&lt;int, int&gt;h;\n        hi(str, h);\n        sort(ans.begin(), ans.end());\n        for (int i = int(ans.size())-1; i&gt;=0; i--)\n        {\n            cout &lt;&lt; ans[i] &lt;&lt; &quot;\\n&quot;;\n        }\n        ans.clear();\n        MAP.clear();\n    }\n}\n\n\/\/ZeroJudge A524\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u912d\u5b78\u9577\u7684\u624b\u6a5f\u88e1\u6709\u4e0d\u53ef\u544a\u4eba\u7684\u79d8\u5bc6\uff0c\u70ba\u4e86\u4e0d\u88ab\u767c\u73fe\u90a3\u4e9b\u7167\u7247\u548c\u7c21\u8a0a\uff0c\u4ed6\u5c0f\u5fc3\u7ffc\u7ffc\u5730\u628a\u624b\u6a5f\u4e0a\u9396\u4e86\u3002\u5e78\u597d\uff0c\u4f60\u662f\u500b\u6703\u5beb\u7a0b\u5f0f\u7684\u5929 [&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":[6],"tags":[21,14,20,8,11,19,12,9],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-6","tag-dfs","tag-map","tag-20","tag-8","tag-11","tag-19","tag-12","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/283","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=283"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":284,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/283\/revisions\/284"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}