{"id":2060,"date":"2021-10-01T23:40:46","date_gmt":"2021-10-01T15:40:46","guid":{"rendered":"http:\/\/47.101.202.111\/?p=2060"},"modified":"2021-10-04T22:37:56","modified_gmt":"2021-10-04T14:37:56","slug":"search-strategy-bfs","status":"publish","type":"post","link":"http:\/\/139.196.114.170\/?p=2060","title":{"rendered":"\u76f2\u76ee\u641c\u7d22 &#8211; BFS\u601d\u60f3\u53ca\u5176\u5e94\u7528"},"content":{"rendered":"<h2>PAT-A1091<\/h2>\n<p>\u5178\u578b\u7684\u641c\u7d22\u6807\u8bb0\u95ee\u9898\uff0c\u9700\u8981\u8003\u8651\u5230\u8fc7\u9ad8\u7684\u9012\u5f52\u6df1\u5ea6 <strong>\u6808\u6ea2\u51fa<\/strong> \u95ee\u9898\uff0c\u56e0\u6b64\u9009\u7528BFS\u7b56\u7565<\/p>\n<hr \/>\n<p><strong>(\u00ac\uff64\u00ac)<\/strong> Q\uff1a\u8fd9\u4e00\u770b\u5c31\u662f\u641c\u7d22\u561b\u2026\u6211\u53c8\u6765\u5543\u8001\u672c\u4e86\uff0c\u53c8\u662f\u6478\u9c7c\u7684\u4e00\u5929<\/p>\n<p><strong>( \u02d9\u706c\u02d9 )<\/strong> A\uff1a\u5662\uff0c\u662f\u561b\uff1f\u5b81\u7528DFS\u7ed9\u6211\u505a\u4e00\u4e2a\u770b\u770b\u2026<\/p>\n<p><strong>\u03a3(\u3063 \u00b0\u0414 \u00b0;)\u3063<\/strong> Q\uff1a\u5367\u69fd\uff1f\u6700\u540e\u4e24\u4e2a\u6837\u4f8b\u6bb5\u9519\u8bef\u4ec0\u4e48\u9b3c\uff0c\u6211\u677f\u513f\u903c\u4fdd\u8bc1\u6570\u7ec4\u6ca1\u8d8a\u754c\uff01<\/p>\n<p><strong>\u256e(\u0e51\u2022\u0301 \u2083\u2022\u0300\u0e51)\u256d<\/strong> A\uff1a\u5b81\u5fd8\u8bb0\u4e86\u9012\u5f52\u6df1\u5ea6\uff0c\u8fd9\u4e2a\u6df1\u5ea6\u53ef\u8fbe $\\scriptsize maxL \\times maxM \\times maxN \\sim 10^8$ \u7684\uff0c\u5de8\u5927\u7684\u6808\u5f00\u9500\uff0c\u518d\u9ad8\u80fd\u7684\u673a\u5668\u4e5f\u5403\u4e0d\u6d88\u554a\uff0c\u8fd9\u5c31\u662f\u8fed\u4ee3\u7684\u4f18\u8d8a\u6027\u54af\uff0c\u8981\u7528BFS\u7684\u54e5<\/p>\n<p><strong>( \u2219\u0306 .\u032f \u2219\u0306 )<\/strong> Q\uff1a\u7b49\u4e0b\uff0c\u8fd9\u4e2a\u63d2\u56fe\u600e\u4e48\u8fd9\u4e48\u8be1\u5f02\uff0c\u8fd9\u662f\u4e09\u7ef4\u63d2\u56fe\u561b\uff0c\u4e09\u7ef4\u7acb\u65b9\u4f53\u6709\u2026\u202619\u4e2a\u90bb\u63a5\u65b9\u5757\uff1f\u8fd9\u4e2a\u524d\u8fdb\u65b9\u5411\u5f97\u5199\u7d2f\u6b7b\u3002<\/p>\n<p><strong>(-_-\u30e1)<\/strong> A\uff1a\u76f2\u751f\uff0c\u4f60\u53d1\u73b0\u4e86\u534e\u70b9\uff01\u4f60\u6210\u529f\u5c06\u9898\u7684\u96be\u5ea6\u8f6c\u79fb\u5230\u4e86\u9898\u610f\u7406\u89e3\u4e0a\uff01\u8fd9\u4e2a\u56fe\u7684\u610f\u601d\uff1a\u76f8\u90bb\u50cf\u7d20\u6307\u7684\u662f\u4e0a\u4e0b\u5de6\u53f3\u524d\u540e=\u3002=\u60f3\u4e0d\u5230\u5427\u2026\u2026\u5b83\u4e0d\u662f\u4f60\u60f3\u8c61\u4e2d\u7684\u90a3\u79cd\u4e09\u7ef4\u626b\u63cf\u65b9\u5757\uff0c\u5c0a\u91cd\u9898\u610f<\/p>\n<p><strong>(@-\uff5e-@)<\/strong> A\uff1a\u54e6\u5bf9\u4e86\uff0c\u6709\u4e2a\u5c0f\u5751\u6ce8\u610f\u522b\u8e29\uff0c\u4e09\u7ef4\u6570\u7ec4\u4e00\u5b9a\u6309\u5c42\u6570L\u3001\u957fM\u3001\u5bbdN\u987a\u5e8f\u58f0\u660e\u548c\u8bbf\u95ee\uff0c\u522b\u7ed9\u4e86\u8f93\u5165\u987a\u5e8f\u5c31\u987a\u624b\u4e86<\/p>\n<hr \/>\n<pre><code class=\"language-cpp \">#include &lt;iostream&gt;\n#include &lt;bits\/stdc++.h&gt;\n#include &lt;queue&gt;\nusing namespace std;\n\nstruct coordinate {\n    int x, y, z;\n};\n\nconst int maxM = 1286, maxN = 128, maxL = 60;\nint cube[maxL][maxM][maxN];\nint cnt = 0, total = 0;\nint M, N, L, T;\nqueue&lt;coordinate&gt; q;\n\nvoid BFS(int i, int j, int k) {\n    q.push({i, j, k});\n    int x, y, z;\n    while (!q.empty()) {\n        coordinate co = q.front();\n        q.pop();\n        x = co.x; y = co.y; z = co.z;\n        if (x &lt; 0 || x == L || y &lt; 0 || y == M || z &lt; 0 || z == N)\n            continue;\n\n        int val = cube[x][y][z];\n        if (val == 0) continue;\n        if (val == 1) {\n            cnt++;\n            cube[x][y][z] = 0;\n            q.push({x + 1, y, z});\n            q.push({x - 1, y, z});\n            q.push({x, y + 1, z});\n            q.push({x, y - 1, z});\n            q.push({x, y, z + 1});\n            q.push({x, y, z - 1});\n        }\n    }\n}\n\nint main() {\n    scanf(\"%d%d%d%d\", &amp;M, &amp;N, &amp;L, &amp;T);\n    memset(cube, 0, sizeof(cube));\n    for (int i = 0; i &lt; L; i++)\n        for (int j = 0; j &lt; M; j++)\n            for (int k = 0; k &lt; N; k++)\n                scanf(\"%d\", &amp;cube[i][j][k]);\n\n    for (int i = 0; i &lt; L; i++)\n        for (int j = 0; j &lt; M; j++)\n            for (int k = 0; k &lt; N; k++)\n                if (cube[i][j][k] != -1) {\n                    cnt = 0;\n                    BFS(i, j, k);\n                    if (cnt &gt;= T) total += cnt;\n                }\n\n    printf(\"%d\\n\", total);\n\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PAT-A1091 \u5178\u578b\u7684\u641c\u7d22\u6807\u8bb0\u95ee\u9898\uff0c\u9700\u8981\u8003\u8651\u5230\u8fc7\u9ad8\u7684\u9012\u5f52\u6df1\u5ea6 \u6808\u6ea2\u51fa \u95ee\u9898\uff0c\u56e0\u6b64\u9009\u7528BFS\u7b56\u7565 (\u00ac\uff64\u00ac) &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/139.196.114.170\/?p=2060\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u76f2\u76ee\u641c\u7d22 &#8211; BFS\u601d\u60f3\u53ca\u5176\u5e94\u7528\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/2060"}],"collection":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2060"}],"version-history":[{"count":3,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/2060\/revisions"}],"predecessor-version":[{"id":2063,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/2060\/revisions\/2063"}],"wp:attachment":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2060"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}