{"id":1178,"date":"2024-09-08T09:00:00","date_gmt":"2024-09-08T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1178"},"modified":"2024-08-22T11:16:34","modified_gmt":"2024-08-22T03:16:34","slug":"zerojudge-e584","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-e584\/","title":{"rendered":"ZeroJudge E584: Continents"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 11094 &#8211; Continents<\/h4>\n\n\n\n<p>Mijid \u5927\u5e1d\u662f Dodars \u9818\u571f\u4e4b\u738b\u3002\u4ed6\u559c\u6b61\u5728\u81ea\u5df1\u9818\u571f\u5167\u7684\u57ce\u5e02\u4e4b\u9593\u65c5\u884c\uff0c\u60a8\u6c38\u9060\u4e0d\u6703\u770b\u5230\u4ed6\u5728\u540c\u4e00\u500b\u57ce\u5e02\u5f85\u8d85\u904e\u4e00\u5929\u3002<br>\u56e0\u6b64\uff0c\u4ed6\u4f54\u9818\u4e86\u4ed6\u7684\u5927\u9678\u7684\u6240\u6709\u9818\u571f\uff01\u5118\u7ba1\u5982\u6b64\uff0c\u4ed6\u9084\u662f\u4e0d\u6eff\u8db3\u65bc\u4ed6\u9818\u571f\u4e0a\u7684\u6240\u6709\u57ce\u5e02\uff0c\u4ed6\u5e0c\u671b\u80fd\u4f54\u9818\u53e6\u4e00\u7247\u65b0\u5927\u9678\uff0c\u4ee5\u4fbf\u6709\u66f4\u591a\u9078\u64c7\u53bb\u65b0\u57ce\u5e02\u3002<br>\u73fe\u5728\uff0c\u6709\u4e86\u4e16\u754c\u5730\u5716\uff0c\u4ed6\u9700\u8981\u60a8\u7684\u5e6b\u52a9\u624d\u80fd\u627e\u5230\u4ed6\u6240\u5c45\u4f4f\u7684\u5927\u9678\u4ee5\u5916\u6700\u5927\u7684\u5927\u9678\u3002<br>\u5730\u5716\u7684\u5927\u5c0f\u70ba M x N\uff0c\u6700\u591a\u5305\u542b\u5169\u500b\u4e0d\u540c\u7684\u5b57\u6bcd\uff0c\u5206\u5225\u8868\u793a\u571f\u5730\u548c\u6c34\u57df\u3002<br>\u5927\u9678\u662f\u4e00\u7d44\u76f8\u9023\u7684\u9678\u5730\u5340\u57df\uff0c\u88ab\u6c34\u57df\u6216\u5730\u5716\u672b\u7aef\u5b8c\u5168\u5305\u570d\u3002\u5982\u679c\u5169\u500b\u5340\u57df\u5177\u6709\u5171\u540c\u7684\u908a\u7de3\uff0c\u5247\u4ee3\u8868\u5b83\u5011\u5f7c\u6b64\u76f8\u9023\u3002<br>\u5de6\u4e0a\u5340\u57df\u7684\u5750\u6a19\u70ba (0, 0)\uff0c\u53f3\u4e0b\u5340\u57df\u7684\u5750\u6a19\u70ba (M-1, N-1)\u3002<br>\u7531\u65bc\u5730\u7403\u662f\u5713\u7684\uff0c\u6240\u4ee5\u5730\u5716\u6700\u5de6\u5340\u57df (x, 0) \u548c\u6700\u53f3\u5340\u57df (x, N-1) \u76f8\u9023\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>EOF \u8f38\u5165\uff0c\u6bcf\u7d44\u6e2c\u8cc7\u7684\u7b2c\u4e00\u884c\u5305\u542b\u5169\u500b\u6574\u6578 M \u548c N (M, N \u2264 20)\u3002<br>\u63a5\u4e0b\u4f86\u6709 M \u884c N \u500b\u5b57\u5143\u7684\u5730\u5716\u3002<br>\u63a5\u4e0b\u4f86\u4e00\u884c\u6709\u5169\u500b\u6574\u6578 X (0 \u2264 X &lt; M) \u548c Y (0 \u2264 Y &lt; N)\u3002<br>(X, Y) \u4ee3\u8868 Mijid \u5927\u5e1d\u7576\u524d\u6240\u5728\u7684\u5340\u57df\u7684\u5750\u6a19\u3002<br>\u6bcf\u7d44\u6e2c\u8cc7\u4e4b\u5f8c\u6709\u4e00\u500b\u7a7a\u767d\u884c\u3002<\/td><td>\u5c0d\u65bc\u6bcf\u7d44\u6e2c\u8cc7\uff0c\u8f38\u51fa\u4e00\u884c Mijid \u5927\u5e1d\u53ef\u4ee5\u4f54\u9818\u7684\u6700\u5927\u9678\u5730\u5340\u57df\u3002<\/td><\/tr><tr><td>5 5<br>wwwww<br>wwllw<br>wwwww<br>wllww<br>wwwww<br>1 3<\/td><td>2<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge E584 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528 BFS \u5148\u627e\u5230\u5927\u5e1d\u76ee\u524d\u6240\u5728\u7684\u5927\u9678\u9762\u7a4d\uff0c\u5927\u9678\u4e26\u6c92\u6709\u7279\u5b9a\u7684\u5b57\u5143\uff0c\u6240\u4ee5\u8f38\u5165\u4e2d X \u548c Y \u7684\u5ea7\u6a19\u4e0a\u7684\u5b57\u5143\u5c31\u662f\u5927\u9678\uff0c\u5176\u4ed6\u90fd\u4e0d\u662f\u3002<\/p>\n\n\n\n<p>\u6574\u5f35\u5730\u5716\u662f\u5de6\u53f3\u76f8\u9023\u7684\uff0c\u6240\u4ee5\u5728\u8dd1 BFS \u7684\u6642\u5019\u8981\u6ce8\u610f\u4e00\u4e0b\u5224\u65b7\u5f0f\u7684\u689d\u4ef6\u3002\u53ef\u4ee5\u5ba3\u544a\u4e00\u500b\u4e8c\u7dad\u9663\u5217\uff0c\u88e1\u9762\u7684\u8cc7\u6599\u90fd\u9810\u8a2d\u70ba 0\uff0c\u53ea\u8981 BFS \u6709\u8dd1\u5230\u9019\u500b\u9ede\u5c31\u5c07\u9019\u500b\u4f4d\u7f6e\u7684\u6578\u503c\u8a2d\u5b9a\u70ba 1\uff0c\u8dd1 BFS \u7684\u904e\u7a0b\u5982\u679c\u8dd1\u5230\u76ee\u524d\u4f4d\u7f6e\u70ba 1 \u7684\u9ede\u5c31\u4e0d\u8981\u7e7c\u7e8c\u8d70\u4e0b\u53bb\uff0c\u4e5f\u4e0d\u8981\u5c07\u8a72\u9ede\u7d00\u9304\u5728\u53ef\u4ee5\u4f54\u9818\u7684\u5340\u57df\u6578\u91cf\u4e2d\u3002<\/p>\n\n\n\n<p>\u627e\u5b8c\u5927\u5e1d\u6240\u8655\u7684\u5927\u9678\u4e4b\u5f8c\u5c31\u8dd1 M\uff0aN \u7684\u8ff4\u5708\uff0c\u5982\u679c\u76ee\u524d\u4f4d\u7f6e\u662f\u5927\u9678\u4e14\u6c92\u6709\u88ab\u8d70\u904e\uff0c\u5247\u4ee5\u9019\u500b\u4f4d\u7f6e\u70ba\u8d77\u9ede\u8dd1 BFS\uff0c\u6bcf\u6b21 BFS \u7d50\u675f\u4e4b\u5f8c\u56de\u50b3\u4e00\u500b\u6578\u5b57\uff0c\u70ba BFS \u8dd1\u5230\u7684\u9ede\u6578\u91cf\uff0c\u4e5f\u5c31\u662f\u5927\u9678\u9762\u7a4d\uff0c\u4e26\u4e14\u5c0b\u627e\u6700\u5927\u7684\u5927\u9678\u9762\u7a4d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=e584\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge E584: Continents<\/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\nint M, N, MAP[50][50] = {};\nstring crater[50] = {};\nchar land;\n\nint BFS(const vector&lt;pair&lt;int, int&gt;&gt;start, int count) {\n    if (start.size() == 0) return count;\n    vector&lt;pair&lt;int, int&gt;&gt;newStart;\n    for (int i = 0; i&lt;start.size(); i++) {\n        const int y = start[i].first, x = start[i].second;\n        if (MAP[y][x] != 0) continue;\n        MAP[y][x]++;\n        count++;\n        if (y - 1 &gt;= 0 && crater[y-1][x] == land && MAP[y-1][x] == 0) newStart.push_back(make_pair(y-1, x));\n        if (y + 1 &lt; M && crater[y+1][x] == land && MAP[y+1][x] == 0) newStart.push_back(make_pair(y+1, x));\n        if (x - 1 &gt;= 0 && crater[y][x-1] == land && MAP[y][x-1] == 0) newStart.push_back(make_pair(y, x-1));\n        else if (x - 1 &lt; 0 && crater[y][N-1] == land && MAP[y][N-1] == 0) newStart.push_back(make_pair(y, N-1));\n        if (x + 1 &lt; N && crater[y][x+1] == land && MAP[y][x+1] == 0) newStart.push_back(make_pair(y, x+1));\n        else if (x + 1 &gt;= N && crater[y][0] == land && MAP[y][0] == 0) newStart.push_back(make_pair(y, 0));\n    }\n    return BFS(newStart, count);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    while (cin &gt;&gt; M &gt;&gt; N) {\n        for (int i = 0; i&lt;M; i++) {\n            cin &gt;&gt; crater[i];\n            for (int j = 0; j&lt;N; j++) {\n                MAP[i][j] = 0;\n            }\n        }\n        int Y, X, ans = 0;\n        cin &gt;&gt; Y &gt;&gt; X;\n        land = crater[Y][X];\n        vector&lt;pair&lt;int, int&gt;&gt;start;\n        start.push_back(make_pair(Y, X));\n        int ownLand = BFS(start, 0);\n        for (int i = 0; i&lt;M; i++) {\n            for (int j = 0; j&lt;N; j++) {\n                if (crater[i][j] == land && MAP[i][j] == 0) {\n                    vector&lt;pair&lt;int, int&gt;&gt;s;\n                    s.push_back(make_pair(i, j));\n                    ans = max(ans, BFS(s, 0));\n                }\n            }\n        }\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge E584\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 11094 &#8211; Continents Mijid \u5927\u5e1d\u662f Dodars \u9818\u571f\u4e4b\u738b\u3002\u4ed6 [&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":[18],"tags":[30,20,22,8,11,13,9],"class_list":["post-1178","post","type-post","status-publish","format-standard","hentry","category-uva","tag-bfs","tag-20","tag-22","tag-8","tag-11","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1178","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=1178"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1178\/revisions"}],"predecessor-version":[{"id":1180,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1178\/revisions\/1180"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}