{"id":959,"date":"2024-06-19T12:04:40","date_gmt":"2024-06-19T04:04:40","guid":{"rendered":"https:\/\/seanxd.com\/?p=959"},"modified":"2024-06-19T12:04:43","modified_gmt":"2024-06-19T04:04:43","slug":"zerojudge-o077","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-o077\/","title":{"rendered":"ZeroJudge O077: Digital Canvas"},"content":{"rendered":"\n\n\n<p>\u6709\u4e00\u500b H\uff0aW \u7684\u96fb\u5b50\u756b\u5e03\uff0c\u4e00\u958b\u59cb\u6578\u503c\u90fd\u662f 0 \u4ee3\u8868\u672a\u586b\u8272\uff0c\u63a5\u4e0b\u4f86\u8acb\u6a21\u64ec N \u6b21\u756b\u7b46\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u6bcf\u6b21\u756b\u7b46\u64cd\u4f5c\u70ba\u9078\u4e00\u500b\u5ea7\u6a19 (R, C) \u505c\u7559 T \u79d2\uff0c\u4ed6\u6703\u5c07\u66fc\u54c8\u9813\u8ddd\u96e2 &lt;= T \u7684\u5340\u584a\u67d3\u4e0a\u984f\u8272 X\u3002<strong>\u82e5\u6709\u591a\u500b\u984f\u8272\u91cd\u8907\u586b\u5230\u76f8\u540c\u5340\u584a\uff0c\u984f\u8272\u7684\u6578\u503c\u6703\u7d2f\u52a0\u8d77\u4f86<\/strong>\u3002<\/p>\n\n\n\n<p>\u8acb\u8f38\u51fa N \u6b21\u64cd\u4f5c\u5f8c\u7684\u756b\u5e03\u72c0\u614b\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>\u7b2c\u4e00\u884c\u8f38\u5165\u4e09\u500b\u6b63\u6574\u6578 H\u3001W\u3001N (1 &lt;= H\u3001W &lt;= 20\uff0c1 &lt;= N &lt;= 100)\u3002<br>\u63a5\u4e0b\u4f86\u6709 N \u884c\uff0c\u6bcf\u4e00\u884c\u6709\u56db\u500b\u6574\u6578 R\u3001C\u3001T\u3001X (0 &lt;= R &lt;= H\uff0c0 &lt;= C &lt;= W\uff0c0 &lt;= t &lt;= 20\uff0c1 &lt;= X &lt;= 10)\u3002<\/td><td>\u8f38\u51fa\u756b\u5e03\u505a N \u6b21\u756b\u7b46\u64cd\u4f5c\u5f8c\u7684\u72c0\u614b\u3002<\/td><\/tr><tr><td>1 20 3<br>0 13 5 7<br>0 6 4 4<br>0 13 12 6<\/td><td>0 6 10 10 10 10 10 10 17 17 17 13 13 13 13 13 13 13 13 6<\/td><\/tr><tr><td>6 7 3<br>3 2 2 1<br>1 6 1 2<br>1 3 2 5<\/td><td>0 0 5 5 5 0 2<br>0 5 6 5 5 7 2<br>0 1 6 6 5 0 2<br>1 1 1 6 1 0 0<br>0 1 1 1 0 0 0<br>0 0 1 0 0 0 0<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge O077 \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 \u7684\u65b9\u5f0f\u4f86\u756b\u756b\uff0c\u7d42\u6b62\u689d\u4ef6\u9664\u4e86\u7576\u6c92\u6709\u8d77\u9ede\u6642\uff0c\u7576\u8dd1 BFS \u7684\u6b21\u6578 >= T \u6642\u4e5f\u8981\u7d42\u6b62\uff0c\u66fc\u54c8\u9813\u8ddd\u96e2\u5176\u5be6\u5c31\u662f\u8d70\u4e86\u5e7e\u6b65\u7684\u610f\u601d\uff0c\u4e5f\u5c31\u662f BFS \u8dd1\u7684\u6b21\u6578\u3002<\/p>\n\n\n\n<p>\u5728 BFS \u7684\u53c3\u6578\u4e2d\u9700\u8981\u6709\u4e00\u500b map \u4f86\u5b58\u53d6\u5df2\u7d93\u8d70\u904e\u54ea\u4e9b\u9ede\u4e86\uff0c\u9019\u908a\u53d6\u540d\u53eb\u505a all\uff0c\u5982\u679c all[\u73fe\u5728\u5ea7\u6a19] == 0 \u624d\u80fd\u7d66\u76ee\u524d\u5ea7\u6a19\u52a0\u4e0a X\uff0c\u4e26\u4e14\u6bcf\u6b21\u8d70\u5230\u4efb\u4f55\u5ea7\u6a19\u90fd\u9700\u8981 all[\u5ea7\u6a19]++\uff0c\u56e0\u70ba<strong>\u5728\u540c\u6a23\u7684\u7b2c N \u6b21 BFS \u4e2d\uff0c\u540c\u4e00\u500b\u9ede\u53ea\u80fd\u88ab\u52a0\u4e00\u6b21 X\uff0c\u4e0d\u80fd\u7d2f\u52a0<\/strong>\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u70ba\u4e86\u907f\u514d\u8d85\u6642\uff0c\u53ef\u4ee5\u5ba3\u544a\u4e00\u500b map \u4f86\u5b58\u53d6\u4e0b\u4e00\u6b21 BFS \u5df2\u7d93\u6709\u7684\u8d77\u9ede\uff0c\u9019\u908a\u53d6\u540d\u53eb\u505a add\u3002\u7576\u65b0\u589e\u4e86\u4e0b\u4e00\u6b21 BFS \u7684\u8d77\u9ede\u6642\uff0cadd[\u5ea7\u6a19]++\uff0c\u4e26\u4e14\u8981\u65b0\u589e\u6642\u9700\u8981\u5224\u65b7 add[\u5ea7\u6a19] \u662f\u5426\u70ba 0\uff0c\u5982\u679c\u662f 0 \u624d\u8981\u65b0\u589e\u9019\u500b\u5ea7\u6a19\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=o077\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge O077: \u96fb\u5b50\u756b\u5e03<\/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;\n#include &lt;map&gt;\nusing namespace std;\n\nint H, W, N, num[30][30] = {}, loc[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\nint R, C, T, X;\n\npair&lt;int, int&gt; axis (const int a, const int b) {\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, map&lt;pair&lt;int, int&gt;, int&gt;MAP, const int time, map&lt;pair&lt;int, int&gt;, int&gt;all) {\n    if (time == T+1) return;\n    if (start.empty()) return;\n    vector&lt;pair&lt;int, int&gt;&gt;newStart;\n    map&lt;pair&lt;int, int&gt;, int&gt;add;\n    for (int i = 0; i&lt;start.size(); i++) {\n        MAP[start[i]]++;\n        const int y = start[i].first, x = start[i].second;\n        if (all[start[i]] == 0) num[y][x] += X;\n        all[start[i]]++;\n        for (int j = 0; j&lt;4; j++) {\n            const int yy = y + loc[j][0], xx = x + loc[j][1];\n            if (yy &gt;= 0 && yy &lt; H && xx &gt;= 0 && x &lt; W && MAP[axis(yy, xx)] == 0 && add[axis(yy, xx)] == 0) {\n                newStart.push_back(axis(yy, xx));\n                add[axis(yy, xx)]++;\n            }\n        }\n    }\n    BFS(newStart, MAP, time+1, all);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    cin &gt;&gt; H &gt;&gt; W &gt;&gt; N;\n    for (int i = 0; i&lt;H; i++) {\n        for (int j = 0; j&lt;W; j++) num[i][j] = 0;\n    }\n    for (int i = 0; i&lt;N; i++) {\n        cin &gt;&gt; R &gt;&gt; C &gt;&gt; T &gt;&gt; X;\n        vector&lt;pair&lt;int, int&gt;&gt;start;\n        start.push_back(axis(R, C));\n        map&lt;pair&lt;int, int&gt;, int&gt;MAP;\n        BFS(start, MAP, 0, MAP);\n    }\n    for (int i = 0; i&lt;H; i++) {\n        for (int j = 0; j&lt;W; j++) cout &lt;&lt; num[i][j] &lt;&lt; &quot; &quot;;\n        cout &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge O077\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4e00\u500b H\uff0aW \u7684\u96fb\u5b50\u756b\u5e03\uff0c\u4e00\u958b\u59cb\u6578\u503c\u90fd\u662f 0 \u4ee3\u8868\u672a\u586b\u8272\uff0c\u63a5\u4e0b\u4f86\u8acb\u6a21\u64ec N \u6b21\u756b\u7b46\u64cd\u4f5c\u3002 \u6bcf\u6b21\u756b\u7b46\u64cd\u4f5c\u70ba\u9078\u4e00 [&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,14,23,20,22,8,9],"class_list":["post-959","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-bfs","tag-map","tag-pair","tag-20","tag-22","tag-8","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/959","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=959"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/959\/revisions"}],"predecessor-version":[{"id":961,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/959\/revisions\/961"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}