{"id":582,"date":"2024-06-18T09:00:00","date_gmt":"2024-06-18T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=582"},"modified":"2024-05-12T21:16:15","modified_gmt":"2024-05-12T13:16:15","slug":"zerojudge-c129","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-c129\/","title":{"rendered":"ZeroJudge C129: Oil Deposits"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 00572 &#8211; Oil Deposits<\/h4>\n\n\n\n<p class=\"\">\u6709\u4e00\u5bb6\u77f3\u6cb9\u516c\u53f8\u8ca0\u8cac\u63a2\u52d8\u67d0\u584a\u5730\u5e95\u4e0b\u7684\u77f3\u6cb9\u542b\u91cf\uff0c\u9019\u584a\u5730\u662f\u77e9\u884c\u7684\uff0c\u4e26\u4e14\u70ba\u4e86\u63a2\u52d8\u7684\u65b9\u4fbf\u88ab\u5207\u5272\u70ba\u8a31\u591a\u5c0f\u584a\u3002\u7136\u5f8c\u4f7f\u7528\u5100\u5668\u5c0d\u6bcf\u500b\u5c0f\u584a\u53bb\u63a2\u52d8\u3002\u542b\u6709\u77f3\u6cb9\u7684\u5c0f\u584a\u7a31\u70ba\u4e00\u500b pocket\u3002\u5047\u5982\u5169\u500b pocket \u76f8\u9023\uff0c\u5247\u9019\u5169\u500b pocket \u5c6c\u65bc\u540c\u4e00\u500b oil deposit\u3002\uff08\u6240\u8b02\u76f8\u9023\u7684\u5b9a\u7fa9\u8207\u8e29\u5730\u96f7\u904a\u6232\u4e2d\u7684\u5b9a\u7fa9\u76f8\u540c\uff0c\u8acb\u53c3\u8003 sample input\u3001sample output\uff09<\/p>\n\n\n\n<p class=\"\">\u4f60\u7684\u4efb\u52d9\u5c31\u662f\u8981\u627e\u51fa\u9019\u584a\u5730\u5305\u542b\u5e7e\u500b\u4e0d\u540c\u7684 oil deposit\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\u7d44\u8cc7\u6599\u7684\u7b2c\u4e00\u884c\u6709 2 \u500b\u6574\u6578 M \u548c N\u3002M \u4ee3\u8868\u9019\u584a\u5730\u7684\u5217\u6578\uff0cN \u4ee3\u8868\u9019\u584a\u5730\u7684\u884c\u6578 (1 &lt;= M\u3001N &lt;= 100)\u3002\u63a5\u4e0b\u4f86\u7684 M \u884c\u5c31\u662f\u9019\u584a\u5730\u63a2\u52d8\u7684\u5167\u5bb9\u3002\u300c@\u300d\u4ee3\u8868\u6b64\u5c0f\u584a\u542b\u77f3\u6cb9\uff0c\u300c*\u300d\u4ee3\u8868\u6b64\u5c0f\u584a\u4e0d\u542b\u77f3\u6cb9\u3002M = 0\u3001N = 0 \u4ee3\u8868\u8f38\u5165\u7d50\u675f\u3002<\/td><td>\u5c0d\u6bcf\u7d44\u6e2c\u8a66\u8cc7\u6599\u8f38\u51fa oil deposit \u7684\u6578\u76ee\u3002<\/td><\/tr><tr><td>1 1<br>*<br>3 5<br><em>@<\/em>@*<br><strong>@<\/strong><br><em>@<\/em>@*<br>1 8<br>@@***<em>@<\/em><br>5 5<br>**<strong>@ *@@*@ *@<\/strong>@<br>@@@<em>@ @@<\/em>*@<br>0 0<\/td><td>0<br>1<br>2<br>2<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge C129 \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 class=\"\">\u6536\u5b8c\u8cc7\u6599\u4e4b\u5f8c\u4e00\u500b\u4e00\u500b\u5b57\u5143\u505a\u5224\u65b7\uff0c\u5982\u679c\u76ee\u524d\u5b57\u5143\u6709\u77f3\u6cb9\uff0c\u5c31\u8dd1 BFS\u3002\u8dd1 BFS \u7684\u6642\u5019\u8981\u8dd1\u300c\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u3001\u53f3\u4e0a\u3001\u53f3\u4e0b\u3001\u5de6\u4e0a\u3001\u5de6\u4e0b\u300d\u516b\u500b\u65b9\u4f4d\uff0c\u4e26\u4e14\u4e0d\u80fd\u8dd1\u5230\u91cd\u8907\u7684\u9ede\u3002\u53ef\u4ee5\u5ba3\u544a\u4e00\u500b Map \u4f86\u5b58\u54ea\u4e9b\u9ede\u5df2\u7d93\u8d70\u904e\u4e86\uff0c\u8981\u6ce8\u610f\u7684\u662f\u9019\u500b Map \u53ef\u4ee5\u8a2d\u6210\u5168\u57df\u8b8a\u6578\uff0c\u9019\u6a23\u5b50 BFS \u7d50\u675f\u5f8c\u8dd1\u5230\u5df2\u7d93\u8d70\u904e\u7684\u9ede\u5c31\u4e0d\u6703\u518d\u9032 BFS\u3002\u6bcf\u7576\u4e00\u500b BFS \u7d50\u675f\u6642\u5c31\u5c07\u7b54\u6848+1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=c129\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge C129: Oil Deposits<\/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\nvector&lt;string&gt;v;\nint N, M, ans = 0, loc[8][2] ={{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, 1}, {1, 1}, {-1, -1}, {1, -1}};\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 BFS(vector&lt;pair&lt;int, int&gt;&gt;start)\n{\n    if (start.size() == 0)\n    {\n        ans++;\n        return;\n    }\n    vector&lt;pair&lt;int, int&gt;&gt;newStart;\n    for (int i = 0; i&lt;start.size(); i++)\n    {\n        MAP[start[i]]++;\n        int y = start[i].first, x = start[i].second;\n        for (int j = 0; j&lt;8; j++)\n        {\n            int yy = y + loc[j][0], xx = x + loc[j][1];\n            if (yy &gt;= 0 && yy &lt; N && xx &gt;= 0 && xx &lt; M && MAP[axis(yy, xx)] == 0 && v[yy][xx] == &#39;@&#39;)\n            {\n                newStart.push_back(axis(yy, xx));\n            }\n        }\n    }\n    BFS(newStart);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    while (cin &gt;&gt; N &gt;&gt; M && N != 0 && M != 0)\n    {\n        v.clear();\n        ans = 0;\n        MAP.clear();\n        for (int i = 0; i&lt;N; i++)\n        {\n            string str;\n            cin &gt;&gt; str;\n            v.push_back(str);\n        }\n        for (int i = 0; i&lt;N; i++)\n        {\n            for (int j = 0; j&lt;M; j++)\n            {\n                if (v[i][j] == &#39;@&#39; && MAP[axis(i, j)] == 0)\n                {\n                    vector&lt;pair&lt;int, int&gt;&gt;start;\n                    start.push_back(axis(i, j));\n                    BFS(start);\n                }\n            }\n        }\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge C129\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 00572 &#8211; Oil Deposits \u6709\u4e00\u5bb6\u77f3\u6cb9\u516c\u53f8\u8ca0\u8cac\u63a2\u52d8\u67d0\u584a\u5730\u5e95\u4e0b\u7684\u77f3\u6cb9\u542b\u91cf [&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,14,23,20,8,11,9],"class_list":["post-582","post","type-post","status-publish","format-standard","hentry","category-uva","tag-bfs","tag-map","tag-pair","tag-20","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/582","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=582"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/582\/revisions"}],"predecessor-version":[{"id":584,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/582\/revisions\/584"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}