{"id":1252,"date":"2024-11-03T09:00:00","date_gmt":"2024-11-03T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1252"},"modified":"2024-10-08T10:44:32","modified_gmt":"2024-10-08T02:44:32","slug":"zerojudge-d626","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-d626\/","title":{"rendered":"ZeroJudge D626: \u5c0f\u756b\u5bb6\u771f\u597d\u7528"},"content":{"rendered":"\n\n\n<p>Windows\u7684\u5c0f\u756b\u5bb6\u771f\u597d\u7528\uff01<br>(\u81f3\u5c11\u5728\u8655\u7406 PrintScreen \u65b9\u9762\u883b\u5feb\u7684\u2026)<br>\u5927\u5bb6\u90fd\u77e5\u9053<br>\u5c0f\u756b\u5bb6\u88e1\u9762\u6709\u4e00\u7a2e\u7e6a\u5716\u5de5\u5177<br>\u53eb\u505a\u6cb9\u6f06\u6876\u5de5\u5177<br>\u53ea\u8981\u9078\u5b9a\u4f60\u8981\u7684\u984f\u8272\u3001\u6cb9\u6f06\u7684\u5730\u9ede\u5c31\u53ef\u4ee5\u9032\u884c\u586b\u8272<br>\u6cb9\u6f06\u6876\u7684\u586b\u8272\u7bc4\u570d\u662f\u53d6\u6c7a\u65bc&#8221;\u540c\u8272\u584a\u76f8\u9130&#8221;\u7684\u539f\u5247<br>\u73fe\u5728\u8acb\u4f60\u6a21\u64ec\u9019\u9805\u5de5\u5177<\/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\u500b\u6e2c\u8cc7\u9ede\u53ea\u6709\u4e00\u7b46\u6e2c\u8cc7\u3002<br>\u7b2c\u4e00\u884c\u6709\u6574\u6578 N (1 &lt;= N &lt;= 100)\u8868\u793a\u9019\u5f35\u5716\u7684\u5927\u5c0f\u662f (N *N) \u500b\u5b57\u5143<br>\u63a5\u4e0b\u4f86\u7684 N \u884c\uff0c\u6bcf\u884c N \u500b\u5b57\u5143\u8868\u793a\u9019\u5f35\u5716\u7684\u6a23\u5b50\u3002<br>\u53ea\u6709\u300c+\u300d\u548c\u300c-\u300d\u5169\u7a2e\u5b57\u5143\u7d44\u6210 (\u5169\u7a2e\u984f\u8272\u7684\u610f\u601d)<br>\u5728\u6700\u5f8c\u4e00\u884c\uff0c\u6709\u5169\u500b\u6574\u6578 i, j \u8868\u793a\u6cb9\u6f06\u6876\u9ede\u64ca\u7684\u5730\u9ede\u662f\u7b2c (i + 1) \u5217\u7b2c (j + 1) \u500b\u5b57\u5143\u3002<br>\u5047\u8a2d\u6709\u5716\u5982\u4e0b 3 * 3\uff1a<br>\u00a0    012<br>0\uff1a&#8212;<br>1\uff1a-+-<br>2\uff1a-++<br>\u90a3\u9ebc 0, 2 \u5c31\u8868\u793a\u9019\u683c\uff1a<br>\u00a0012<br>0&#8211;*<br>1-+-<br>2-++<br>\u8acb\u8996\u9078\u53d6\u7684\u984f\u8272\u70ba\u300c+\u300d\uff0c\u9078\u53d6\u7684\u4f4d\u7f6e\u539f\u672c\u7684\u984f\u8272\u5fc5\u70ba\u300c-\u300d\u3002<br>\u4e26\u4e14\u58a8\u6c34\u53ea\u6703\u5229\u7528\u4e0a\u4e0b\u5de6\u53f3\u56db\u500b\u65b9\u4f4d\u64f4\u6563\u3002<\/td><td>\u8acb\u76f4\u63a5\u8f38\u51fa\u7d93\u904e\u6cb9\u6f06\u6876\u5857\u8272\u5f8c\u7684\u5716\u6848\u3002<\/td><\/tr><tr><td>7<br>-+++&#8212;<br>-+&#8211;+&#8211;<br>-+&#8212;+-<br>&#8211;+++&#8211;<br>&#8212;++&#8211;<br>3 4<\/td><td><br>-+++&#8212;<br>-++++&#8211;<br>-+++++-<br>&#8211;+++&#8211;<br>&#8212;++&#8211;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528 BFS\uff0c\u4e26\u4e14\u8981\u7d00\u9304\u6bcf\u4e00\u6b21\u8d70\u904e\u7684\u9ede\uff0c\u53ea\u8981\u8d70\u904e\u5c31\u4e0d\u80fd\u518d\u8d70\uff0c\u4e0d\u80fd\u6703\u9020\u6210\u7121\u7aae\u8ff4\u5708\u3002\u53e6\u5916\uff0c\u6bcf\u8d70\u5230\u4e00\u500b\u9ede\u5c31\u8981\u5c07\u76ee\u524d\u4f4d\u7f6e\u7684\u5b57\u5143\u6539\u6210\u300c+\u300d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=d626\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge D626: \u5c0f\u756b\u5bb6\u771f\u597d\u7528<\/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 N, walk[200][200] = {}, loc[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\nchar draw[200][200] = {};\n\nvoid BFS(const vector&lt;pair&lt;int, int&gt;&gt;start) {\n    if (start.size() == 0) return;\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        walk[y][x]++;\n        draw[y][x] = &#39;+&#39;;\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; N && xx &gt;= 0 && xx &lt; N && draw[yy][xx] == &#39;-&#39; && walk[yy][xx] == 0) {\n                newStart.push_back(make_pair(yy, xx));\n            }\n        }\n    }\n    BFS(newStart);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    cin &gt;&gt; N;\n    for (int i = 0; i&lt;N; i++) {\n        for (int j = 0; j&lt;N; j++) {\n            cin &gt;&gt; draw[i][j];\n            walk[i][j] = 0;\n        }\n    }\n    vector&lt;pair&lt;int, int&gt;&gt;start;\n    int x, y;\n    cin &gt;&gt; x &gt;&gt; y;\n    start.push_back(make_pair(x, y));\n    BFS(start);\n    for (int i = 0; i&lt;N; i++) {\n        for (int j = 0; j&lt;N; j++) {\n            cout &lt;&lt; draw[i][j];\n        }\n        cout &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge D626\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Windows\u7684\u5c0f\u756b\u5bb6\u771f\u597d\u7528\uff01(\u81f3\u5c11\u5728\u8655\u7406 PrintScreen \u65b9\u9762\u883b\u5feb\u7684\u2026)\u5927\u5bb6\u90fd\u77e5\u9053\u5c0f\u756b\u5bb6\u88e1\u9762\u6709\u4e00\u7a2e\u7e6a [&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":[6],"tags":[30,23,22,8,11,9],"class_list":["post-1252","post","type-post","status-publish","format-standard","hentry","category-6","tag-bfs","tag-pair","tag-22","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=1252"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1252\/revisions"}],"predecessor-version":[{"id":1253,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1252\/revisions\/1253"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=1252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=1252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=1252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}