{"id":1140,"date":"2024-08-26T09:00:00","date_gmt":"2024-08-26T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1140"},"modified":"2024-07-26T19:43:12","modified_gmt":"2024-07-26T11:43:12","slug":"zerojudge-k650","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-k650\/","title":{"rendered":"ZeroJudge K650: Queen Bee"},"content":{"rendered":"\n\n\n<p>\u79d1\u5b78\u5bb6\u767c\u73fe\u4e86\u4e00\u7a2e\u65b0\u578b\u7684\u871c\u8702\uff0c\u5b83\u5011\u7684\u8702\u5de2\u7d50\u69cb\u70ba\u7acb\u65b9\u9ad4\uff0c\u8702\u5de2\u88ab\u8702\u5de2\u58c1\u5206\u5272\u70ba\u597d\u5e7e\u500b\u5c0f\u7a7a\u9593\uff0c\u800c\u8702\u540e\u4f4f\u5728\u8702\u5de2\u5167\u6700\u5927\u7684\u7a7a\u9593\u4e2d\u3002\u4eca\u65e5\u70ba\u4e86\u7814\u7a76\u9019\u7a2e\u871c\u8702\uff0c\u9700\u627e\u5230\u8702\u5de2\u4e2d\u7684\u6700\u5927\u7a7a\u9593\uff0c\u4ee5\u78ba\u8a8d\u8702\u540e\u4f4d\u7f6e\u3002\u8702\u5de2\u7684\u9577\u5ea6\u70ba \uff2c\uff0c\u5bec\u5ea6\u70ba \uff37\uff0c\u9ad8\u5ea6\u70ba \uff28\uff0c\u8acb\u4f60\u5beb\u4e00\u500b\u7a0b\u5f0f\u8a08\u7b97\u8702\u5de2\u4e2d\u7684\u6700\u5927\u7a7a\u9593\u70ba\u591a\u5c11\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>\u6bcf\u7b46\u6e2c\u8a66\u8cc7\u6599\u70ba\u4e8c\u5217\uff1a<br>\u7b2c\u4e00\u5217\u6709\u4e09\u500b\u6b63\u6574\u6578 L\u3001W\u3001H\uff081 &lt;= L\u3001W\u3001H &lt;= 135\uff09\uff0c\uff2c\u3001\uff37\u3001\uff28 \u4ee3\u8868\u8702\u5de2\u7684\u9577\u3001\u5bec\u3001\u9ad8\u3002<br>\u7b2c\u4e8c\u5217\u5171\u6709 L\uff0aW\uff0aH \u500b\u5b57\u5143\uff0c\u524d L\uff0aW \u500b\u5b57\u5143\u70ba\u8702\u5de2\u7684\u7b2c\u4e00\u5c64\uff0c\u63a5\u4e0b\u4f86 L\uff0aW \u500b\u5b57\u5143\u70ba\u8702\u5de2\u7684\u7b2c\u4e8c\u5c64\uff0c\u4ee5\u6b64\u985e\u63a8\u3002\u6bcf\u500b\u5b57\u5143\u53ef\u4ee5\u662f 0 \u6216 1\uff0c1 \u4ee3\u8868\u8702\u5de2\u58c1\uff0c0 \u4ee3\u8868\u8702\u5de2\u4e2d\u7684\u7a7a\u9593\u3002<\/td><td>\u5c0d\u6bcf\u7b46\u8cc7\u6599\u8acb\u8f38\u51fa\u4e00\u5217\uff0c\u8acb\u8f38\u51fa\u8702\u5de2\u4e2d\u7684\u6700\u5927\u7a7a\u9593\u3002<\/td><\/tr><tr><td>3 3 3<br>010101010001001111111101111<\/td><td>7<\/td><\/tr><tr><td>1 2 4<br>10000100<\/td><td>6<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge K650 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<p>\u4ee5\u8f38\u5165\u7bc4\u4f8b 1 \u70ba\u4f8b\uff0c\u5247\u8702\u5de2\u7d50\u69cb\u5982\u4e0b\u5716\u6240\u793a\uff0c\u8702\u540e\u6240\u5728\u7684\u7a7a\u9593\u70ba\u7070\u8272\u5340\u57df\uff0c\u5171\u6709\u4e03\u683c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"487\" height=\"295\" loading=\"lazy\" src=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/07\/image-4.png\" alt=\"ZeroJudge K650 \u6e2c\u8cc7\u89e3\u8aaa\" class=\"wp-image-1142\" srcset=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/07\/image-4.png 487w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/07\/image-4-300x182.png 300w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/07\/image-4-18x12.png 18w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/07\/image-4-50x30.png 50w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/07\/image-4-100x61.png 100w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528 BFS\uff0c\u4f46\u662f\u9019\u500b BFS \u4e0d\u6703\u6709\u905e\u8ff4\u7684\u6210\u5206\uff0c\u5c07\u6bcf\u4e00\u6b21\u7684\u8d77\u9ede\u90fd\u5b58\u653e\u5230\u540c\u4e00\u500b\u9663\u5217\u4e2d\uff0c\u9019\u6a23\u5b50 BFS \u4e2d\u7684\u8d77\u9ede\u8ff4\u5708\u5c31\u6703\u4e00\u76f4\u8dd1\u76f4\u5230\u6c92\u6709\u9ede\u70ba\u6b62\uff0c\u4e26\u4e14\u9700\u8981\u7d00\u9304\u6bcf\u4e00\u500b\u9ede\u662f\u5426\u6709\u8d70\u904e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=k650\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge K650: \u5c0b\u627e\u8702\u540e (Queen bee)<\/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;\n#include &lt;vector&gt;\nusing namespace std;\n\nstruct pos{\n    int H;\n    int L;\n    int W;\n    bool operator&lt;(const pos& other) const {\n        if (H != other.H) return H &lt; other.H;\n        if (L != other.L) return L &lt; other.L;\n        return W &lt; other.W;\n    }\n};\n\nchar bee[500][500][500] = {};\nbool MAP[500][500][500] = {};\nint L, W, H, ans = -999;\n\npos p (const int a, const int b, const int c) {\n    pos tmp;\n    tmp.H = a;\n    tmp.L = b;\n    tmp.W = c;\n    return tmp;\n}\n\nvoid BFS(vector&lt;pos&gt;start, int count) {\n    for (int i = 0; i&lt;start.size(); i++) {\n        const int h = start[i].H, l = start[i].L, w = start[i].W;\n        if (MAP[h][l][w]) continue;\n        MAP[h][l][w] = true;\n        count++;\n        if (h - 1 &gt;= 0 && !MAP[h-1][l][w] && bee[h-1][l][w] == &#39;0&#39;) {\n            start.push_back(p(h-1, l, w));\n        }\n        if (h + 1 &lt; H && !MAP[h+1][l][w] && bee[h+1][l][w] == &#39;0&#39;) {\n            start.push_back(p(h+1, l, w));\n        }\n        if (l - 1 &gt;= 0 && !MAP[h][l-1][w] && bee[h][l-1][w] == &#39;0&#39;) {\n            start.push_back(p(h, l-1, w));\n        }\n        if (l + 1 &lt; L && !MAP[h][l+1][w] && bee[h][l+1][w] == &#39;0&#39;) {\n            start.push_back(p(h, l+1, w));\n        }\n        if (w - 1 &gt;= 0 && !MAP[h][l][w-1] && bee[h][l][w-1] == &#39;0&#39;) {\n            start.push_back(p(h, l, w-1));\n        }\n        if (w + 1 &lt; W && !MAP[h][l][w+1] && bee[h][l][w+1] == &#39;0&#39;) {\n            start.push_back(p(h, l, w+1));\n        }\n    }\n    ans = max(ans, count);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    cin &gt;&gt; L &gt;&gt; W &gt;&gt; H;\n    for (int i = 0; i&lt;H; i++) {\n        for (int j = 0; j&lt;L; j++) {\n            for (int k = 0; k&lt;W; k++) {\n                cin &gt;&gt; bee[i][j][k];\n                MAP[i][j][k] = false;\n            }\n        }\n    }\n    for (int i = 0; i&lt;L; i++) {\n        for (int j = 0; j&lt;W; j++) {\n            if (bee[0][i][j] == &#39;0&#39;) {\n                vector&lt;pos&gt;start;\n                start.push_back(p(0, i, j));\n                BFS(start, 0);\n            }\n        }\n    }\n    cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge K650\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u79d1\u5b78\u5bb6\u767c\u73fe\u4e86\u4e00\u7a2e\u65b0\u578b\u7684\u871c\u8702\uff0c\u5b83\u5011\u7684\u8702\u5de2\u7d50\u69cb\u70ba\u7acb\u65b9\u9ad4\uff0c\u8702\u5de2\u88ab\u8702\u5de2\u58c1\u5206\u5272\u70ba\u597d\u5e7e\u500b\u5c0f\u7a7a\u9593\uff0c\u800c\u8702\u540e\u4f4f\u5728\u8702\u5de2\u5167\u6700\u5927\u7684\u7a7a\u9593 [&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":[25],"tags":[30,27,39,8,34,9],"class_list":["post-1140","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-bfs","tag-struct","tag-39","tag-8","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1140","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=1140"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1140\/revisions"}],"predecessor-version":[{"id":1143,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1140\/revisions\/1143"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}