{"id":534,"date":"2024-06-04T09:00:00","date_gmt":"2024-06-04T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=534"},"modified":"2024-05-09T13:29:13","modified_gmt":"2024-05-09T05:29:13","slug":"zerojudge-b683","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-b683\/","title":{"rendered":"ZeroJudge B683: \u74b0\u5f62\u5075\u6e2c"},"content":{"rendered":"\n\n\n<p class=\"\">\u70ba\u4e86\u505a\u7814\u7a76\uff0c\u6e90\u5916\u8001\u6559\u6388\u5f04\u5230\u4e86\u4e00\u53f0\u7279\u6b8a\u7684 DNA \u6383\u63cf\u5100\uff0c\u9019\u53f0\u6a5f\u5668\u53ef\u4ee5\u628a\u76ee\u524d\u7372\u5f97\u7684 DNA \u5011\u5206\u96e2\u6210\u4e00\u500b\u500b\u7684\u5c0f\u7247\u6bb5\uff0c\u4e4b\u5f8c\u62cd\u5f35\u7167\u7247\u4f5c\u70ba\u6383\u63cf\u7d50\u679c\uff0c\u62ff\u4f86\u5206\u6790\u8207\u7814\u7a76\u3002<\/p>\n\n\n\n<p class=\"\">\u6383\u63cf\u7d50\u679c\u6703\u662f\u9ad8\u5ea6\u70ba H\u3001\u5bec\u5ea6\u70ba W \u7684\u77e9\u5f62\u65b9\u683c\uff0c\u6bcf\u500b\u65b9\u683c\u53ef\u80fd\u6709\u5169\u7a2e\u72c0\u614b\uff1a\u300c\u6709 DNA\u300d\u6216\u300c\u7121 DNA\u300d\u3002\u5728\u6240\u7372\u5f97\u7684\u7d50\u679c\u4e2d\uff0c\u5982\u679c\u5169\u500b\u4e0a\u3001\u4e0b\u3001\u5de6\uff0c\u53f3\u76f8\u9130\u7684\u65b9\u683c\u90fd\u6eff\u8db3\u300c\u6709 DNA\u300d\uff0c\u90a3\u9ebc\u7a31\u4f5c\u9019\u5169\u683c\u7684 DNA \u70ba\u806f\u901a\u7684\u3002\u6240\u6709\u76f4\u63a5\u6216\u9593\u63a5\u806f\u901a\uff0c\u4e14\u6eff\u8db3\u300c\u6709DNA\u300d\u7684\u65b9\u683c\uff0c\u5247\u5c6c\u65bc\u540c\u4e00\u500b\u7247\u6bb5\u3002\u5982\u679c\u5169\u500b\u300c\u6709 DNA\u300d\u7684\u65b9\u683c\u5b8c\u5168\u6c92\u6709\u9023\u901a\uff0c\u5247\u5c6c\u65bc\u4e0d\u540c\u7247\u6bb5\u3002\u63db\u53e5\u8a71\u8aaa\uff0c\u7247\u6bb5\u7531\u8a31\u591a\u76f4\u63a5\u6216\u9593\u63a5\u9023\u901a\u800c\u300c\u6709 DNA\u300d\u7684\u4e00\u4e9b\u65b9\u683c\u6240\u7d44\u6210\u3002<\/p>\n\n\n\n<p class=\"\">\u5df2\u77e5\u6bcf\u500b\u7247\u6bb5\u7684\u9577\u76f8\u53ea\u6709\u300c\u7dda\u5f62\u300d\u8207\u300c\u74b0\u5f62\u300d\u5169\u7a2e\u53ef\u80fd\u3002<\/p>\n\n\n\n<p class=\"\">\u300c\u7dda\u5f62\u300d\u7684\u7247\u6bb5\u70ba\u4e00\u689d\u93c8\uff0c\u4e5f\u5373\u53ef\u4ee5\u5728\u6b64\u7247\u6bb5\u4e2d\u627e\u5230\u6070\u597d\u4e00\u500b\u8d77\u59cb\u65b9\u683c\uff0c\u63a5\u8457\u6cbf\u8457\u552f\u4e00\u7684\u65b9\u5411\uff0c\u4f9d\u5e8f\u627e\u5c0b\u4e0b\u4e00\u500b\u65b9\u683c\uff0c\u76f4\u5230\u9047\u5230\u6700\u5f8c\u4e00\u500b\u65b9\u683c\u70ba\u6b62\uff0c\u4e14\u6b64\u65b9\u683c\u8207\u8d77\u59cb\u65b9\u683c\u4e0d\u6703\u4e0a\u3001\u4e0b\u3001\u5de6\uff0c\u53f3\u76f8\u81e8\u3002\u4fdd\u8b49\u5728\u627e\u5c0b\u65b9\u683c\u7684\u904e\u7a0b\u4e2d\u4e0d\u6703\u9047\u5230\u4efb\u4f55\u5c94\u8def\uff0c\u4e14\u6b64\u7247\u6bb5\u81f3\u5c11\u5305\u542b 2 \u683c\u3002<\/p>\n\n\n\n<p class=\"\">\u300c\u74b0\u5f62\u300d\u7684\u7247\u6bb5\u70ba\u4e00\u500b\u74b0\uff0c\u4e5f\u5373\u5728\u6b64\u7247\u6bb5\u4e2d\uff0c\u6bcf\u500b\u65b9\u683c\u90fd\u53ef\u4ee5\u8996\u70ba\u8d77\u59cb\u65b9\u683c\uff0c\u5f9e\u8d77\u59cb\u65b9\u683c\u51fa\u767c\uff0c\u5f9e\u6070\u5169\u500b\u65b9\u5411\u4e2d\u4efb\u9078\u4e00\u500b\u524d\u9032\uff0c\u63a5\u8457\u6cbf\u8457\u552f\u4e00\u7684\u65b9\u5411\uff0c\u4f9d\u5e8f\u627e\u5c0b\u4e0b\u4e00\u500b\u65b9\u683c\uff0c\u76f4\u5230\u9047\u5230\u6700\u5f8c\u4e00\u500b\u65b9\u683c\u70ba\u6b62\uff0c\u6b64\u65b9\u683c\u6703\u8207\u8d77\u59cb\u65b9\u683c\u4e0a\u3001\u4e0b\u3001\u5de6\uff0c\u53f3\u76f8\u81e8\u3002\u4fdd\u8b49\u5728\u627e\u5c0b\u65b9\u683c\u7684\u904e\u7a0b\u4e2d\u4e0d\u6703\u9047\u5230\u5c94\u8def\uff0c\u5f9e\u8d77\u59cb\u65b9\u683c\u51fa\u767c<strong>\u5fc5\u5b9a\u6070\u6709\u5169\u500b\u53ef\u80fd\u7684\u627e\u5c0b\u65b9\u5411<\/strong>\uff0c\u4e14\u6b64\u7247\u6bb5<strong>\u81f3\u5c11\u5305\u542b 8 \u683c<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u5728\u9019\u6b21\u7684\u7814\u7a76\u4e2d\uff0c\u6e90\u5916\u8001\u982d\u4e0d\u95dc\u5fc3\u4efb\u4f55\u300c\u7dda\u5f62\u300d\u7684\u7247\u6bb5\uff0c\u4f46\u60f3\u8981\u597d\u597d<strong>\u5206\u6790\u300c\u74b0\u5f62\u300d\u7684\u7247\u6bb5<\/strong>\uff0c\u7531\u65bc\u9019\u4e9b\u8cc7\u6599\u592a\u904e\u65bc\u9f90\u5927\u4e86\uff0c\u4f60\u5e0c\u671b\u5beb\u4e00\u652f\u7a0b\u5f0f\u5354\u52a9\u5206\u6790\u9019\u4e9b\u7d50\u679c\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>\u8f38\u5165\u7684\u7b2c\u4e00\u5217\u70ba\u5169\u500b\u6b63\u6574\u6578 H \u548c W\uff0c\u8868\u793a\u6383\u63cf\u7d50\u679c\u70ba\u9ad8\u5ea6 H\u3001\u5bec\u5ea6 W \u7684\u77e9\u5f62\u65b9\u683c\u3002<br>\u63a5\u8457\u5171\u6709 H \u5217\uff0c\u6bcf\u5217\u5747\u6070\u6709 W \u500b\u5b57\u5143\uff0c\u5176\u4e2d\u5b57\u5143\u300c.\u300d\uff08\u4e0d\u542b\u5f15\u865f\uff09\u8868\u793a\u8a72\u683c\u300c\u6709 DNA\u300d\uff0c\u5b57\u5143\u300c#\u300d\uff08\u4e0d\u542b\u5f15\u865f\uff09\u8868\u793a\u8a72\u683c\u300c\u7121 DNA\u300d\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u8a72\u5217\u4e0d\u6703\u6709\u5176\u4ed6\u7684\u5b57\u5143\u3002<\/td><td>\u8acb\u8f38\u51fa\u4e00\u5217\uff0c\u5176\u4e2d\u5305\u542b\u4e09\u500b\u6b63\u6574\u6578 X\u3001Y\u3001Z\uff0c\u4e26\u4ee5\u4e00\u500b\u7a7a\u767d\u9694\u958b\uff0c\u8868\u793a\u7e3d\u5171\u6709 X \u500b\u300c\u74b0\u5f62\u300d\u7247\u6bb5\uff0c\u9019\u4e9b\u7247\u6bb5\u9577\u5ea6\u7684\u7e3d\u548c\u70ba Y\uff0c\u4e58\u7a4d\u70ba Z\u3002\u4fdd\u8b49\u81f3\u5c11\u6709\u4e00\u500b\u300c\u74b0\u5f62\u300d\u7247\u6bb5\uff0c\u4e14\u6eff\u8db3 Z &lt; 2<sup>64<\/sup>\u3002<\/td><\/tr><tr><td>3 3<br>&#8230;<br>.#.<br>&#8230;<\/td><td>1 8 8<\/td><\/tr><tr><td>5 6<br>######<br>&#8230;#..<br>.#.###<br>&#8230;#.#<br>####.#<\/td><td>1 8 8<\/td><\/tr><tr><td>11 7<br>&#8230;&#8230;.<br>.#####.<br>.#&#8230;#.<br>.#.#.#.<br>.#&#8230;#.<br>.#####.<br>&#8230;&#8230;.<br>#######<br>#&#8230;.#.<br>..##.#.<br>.###&#8230;<\/td><td>2 32 192<\/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 DFS\uff0c\u6bcf\u6b21\u5f9e\u4e3b\u7a0b\u5f0f\u547c\u53eb DFS \u7684\u6642\u5019\u7d00\u9304\u76ee\u524d\u7684\u9663\u5217\u4f4d\u7f6e\uff0c\u7576 DFS \u8d70\u56de\u8d77\u9ede\u7684\u6642\u5f8c\u5224\u65b7\u8d70\u7684\u6b65\u6578\u662f\u5426 >= 4\uff0c\u5982\u679c >= 4 \u7684\u8a71\u5c31\u4ee3\u8868\u8d70\u4e86\u4e00\u5708\uff0c\u5c07\u8d70\u7684\u6b65\u6578\u5b58\u5230\u4e00\u500b\u9663\u5217\u4e2d\u3002\u8d70 DFS \u7684\u6642\u5019\u512a\u5148\u5224\u65b7\u662f\u5426\u53ef\u4ee5\u5f80\u4e0b\u6216\u53f3\u8d70\uff0c\u53ea\u8981\u8d70\u4e86\u4e00\u6b65\u5c31 break \u8ff4\u5708\u3002<\/p>\n\n\n\n<p class=\"\">\u5c07\u7b54\u6848\u9663\u5217\u7684\u9577\u5ea6\u8f38\u51fa\u8a2d\u5b9a\u70ba X\uff0c\u9663\u5217\u4e2d\u8cc7\u6599\u7e3d\u548c\u8a2d\u5b9a\u70ba Y\uff0c\u9663\u5217\u4e2d\u6240\u6709\u8cc7\u6599\u7684\u4e58\u7a4d\u8a2d\u5b9a\u70ba Z\u3002\u53e6\u5916\uff0c<strong>\u56e0\u70ba\u4e58\u7a4d\u6703\u5f88\u5927\u6240\u4ee5\u9700\u8981\u4f7f\u7528 Unsigned Long Long Int<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=b683\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge B683: \u74b0\u5f62\u5075\u6e2c<\/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;\nusing namespace std;\n\nint H, W, loc[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\nvector&lt;string&gt;num;\nvector&lt;unsigned long long int&gt;ans;\nmap&lt;pair&lt;int, int&gt;, int&gt;MAP;\n\npair&lt;int, int&gt; axis (int a, int b)\n{\n    pair&lt;int, int&gt;tmp;\n    tmp.first = a;\n    tmp.second = b;\n    return tmp;\n}\n\nvoid DFS(pair&lt;int, int&gt;point, pair&lt;int, int&gt;start, unsigned long long int count)\n{\n    MAP[point]++;\n    if (point == start && MAP[point] == 1 && count &gt;= 4)\n    {\n        ans.push_back(count);\n        return;\n    }\n    for (int i = 0; i&lt;4; i++)\n    {\n        int yy = point.first + loc[i][0], xx = point.second + loc[i][1];\n        if (yy &gt;= 0 && yy &lt; H && xx &gt;= 0 && xx &lt; W && num[yy][xx] == &#39;.&#39; && MAP[axis(yy, xx)] == 0)\n        {\n            DFS(axis(yy, xx), start, count+1);\n            return;\n        }\n    }\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    cin &gt;&gt; H &gt;&gt; W;\n    for (int i = 0; i&lt;H; i++)\n    {\n        string str;\n        cin &gt;&gt; str;\n        num.push_back(str);\n    }\n    for (int i = 0; i&lt;H; i++)\n    {\n        for (int j = 0; j&lt;W; j++)\n        {\n            if (MAP[axis(i, j)] == 0 && num[i][j] == &#39;.&#39;)\n            {\n                MAP[axis(i, j)]--;\n                DFS(axis(i, j), axis(i, j), 0);\n            }\n        }\n    }\n    cout &lt;&lt; ans.size();\n    unsigned long long int Y = 0, Z = 1;\n    for (int i = 0; i&lt;ans.size(); i++)\n    {\n        Y += ans[i];\n        Z *= ans[i];\n    }\n    cout &lt;&lt; &quot; &quot; &lt;&lt; Y &lt;&lt; &quot; &quot; &lt;&lt; Z &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge B683\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u70ba\u4e86\u505a\u7814\u7a76\uff0c\u6e90\u5916\u8001\u6559\u6388\u5f04\u5230\u4e86\u4e00\u53f0\u7279\u6b8a\u7684 DNA \u6383\u63cf\u5100\uff0c\u9019\u53f0\u6a5f\u5668\u53ef\u4ee5\u628a\u76ee\u524d\u7372\u5f97\u7684 DNA \u5011\u5206\u96e2\u6210\u4e00\u500b\u500b\u7684\u5c0f\u7247 [&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":[21,14,23,35,20,8,11,9],"class_list":["post-534","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-dfs","tag-map","tag-pair","tag-unsigned-long-long-int","tag-20","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=534"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/534\/revisions"}],"predecessor-version":[{"id":536,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/534\/revisions\/536"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}