{"id":369,"date":"2024-04-28T21:45:57","date_gmt":"2024-04-28T13:45:57","guid":{"rendered":"https:\/\/seanxd.com\/?p=369"},"modified":"2024-04-28T21:45:59","modified_gmt":"2024-04-28T13:45:59","slug":"zerojudge-d821","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-d821\/","title":{"rendered":"ZeroJudge D821: \u6700\u77ed\u8def\u5f91\u500b\u6578"},"content":{"rendered":"\n\n\n<p class=\"\">\u5730\u5716\u4e0a\uff0c\u7531 (S<sub>x<\/sub>, S<sub>y<\/sub>) \u53ea\u80fd\u4e0a\u4e0b\u5de6\u53f3\u5230\u9054 (E<sub>x<\/sub>, E<sub>y<\/sub>) \u7684\u6700\u77ed\u8def\u5f91\u9577<\/p>\n\n\n\n<p class=\"\">\u60f3\u5fc5\u5927\u5bb6\u90fd\u5df2\u7d93\u4e0d\u964c\u751f\u4e86\uff0c\u90a3\u9ebc\u73fe\u5728\u8acb\u5beb\u51fa<\/p>\n\n\n\n<p class=\"\">(S<sub>x<\/sub>, S<sub>y<\/sub>) \u2192 (E<sub>x<\/sub>, E<sub>y<\/sub>) \u7684\u6700\u77ed\u8def\u5f91\u500b\u6578<\/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\u6e2c\u8cc7\u7b2c\u4e00\u884c\u6709\u5169\u500b\u6574\u6578 <strong>N \u548c M<\/strong> (1 \u2266 N,  M \u2266 50)<br>\u63a5\u4e0b\u4f86\u6703\u6709 N \u884c<br>\u6bcf\u884c\u4e0a\u5206\u5225\u6709 M \u500b 0 \u548c 1 \u69cb\u6210\u7684\u5730\u5716<br>0 \u4ee3\u8868\u53ef\u4ee5\u901a\u884c\uff0c1 \u4ee3\u8868\u6709\u969c\u7919\u7269<br>\u63a5\u4e0b\u4f86\u9084\u6703\u6709\u4e00\u884c\u6709\u56db\u500b\u6578\u5b57\uff1aSx\u3001Sy\u3001Ex\u3001Ey<br>0 \u2266 Sx, Ex &lt; N\uff0c0 \u2266 Sy, Ey &lt; M<br>\u5de6\u4e0a\u89d2\u70ba (0, 0)\uff0c\u53f3\u4e0b\u89d2\u70ba (N-1, M-1)<\/td><td>\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8acb\u8f38\u51fa<strong> Mod 100000<\/strong> \u5f8c\u7684\u7d50\u679c<\/td><\/tr><tr><td><strong>5  5<\/strong><br>0  0  0  0  0<br>0  0  0  0  0<br>0  0  0  0  0<br>0  0  0  0  0<br>0  0  0  0  0<br>0  0  4  4<br><strong>6  5<\/strong><br>0  0  0  0  0<br>0  1  0  1  0<br>0  1  1  1  0 <br>0  0  1  1  0<br>0  1  1  0  0<br>0  0  0  0  0<br>0  4  5  0<br><strong>6  5<\/strong><br>0  0  0  0  0<br>0  1  0  1  0<br>0  1  0  1  0<br>0  0  0  1  0<br>0  1  0  0  0<br>0  0  0  0  0<br>0  4  5  0<\/td><td>70<br>3<br>6<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge D821 \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=\"\">\u5148\u9810\u8a2d\u4e00\u500b N\uff0aM \u7684\u4e8c\u7dad\u9663\u5217\u4e26\u4e14\u5c07\u88e1\u9762\u7684\u8cc7\u6599\u9810\u8a2d\u70ba 0\uff0c\u4e26\u4e14\u5c07\u8d77\u9ede\u4f4d\u7f6e\u7684\u503c\u8b8a\u6210 1\u3002\u548c\u666e\u901a\u7684 BFS \u5dee\u4e0d\u591a\uff0c\u53ea\u662f\u5728\u6bcf\u6b21\u5224\u65b7\u53ef\u4ee5\u5f80\u67d0\u500b\u65b9\u5411\u8d70\u7684\u6642\u5019\u8981\u5728\u65b0\u7684\u9ede\u4e0a\u52a0\u4e0a\u539f\u5148\u76ee\u524d\u7684\u9ede\u4e2d\u7684\u503c\u3002\u53e6\u5916\uff0c\u6700\u5f8c 4 \u500b\u6578\u5b57\u662f y, x, y, x\uff0c\u800c\u4e0d\u662f x, y, x, y\uff0c\u9019\u9ede\u9700\u6ce8\u610f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=d821\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge D821: \u6700\u77ed\u8def\u5f91\u500b\u6578<\/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\nint N, M;\nvector&lt;vector&lt;int&gt;&gt;v;\nvector&lt;vector&lt;long long int&gt;&gt;value;\npair&lt;int, int&gt;start, finish;\nmap&lt;pair&lt;int, int&gt;, int&gt;MAP;\nint loc[4][2] = {{0,-1} , {-1,0} , {1,0} , {0,1}};\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;begin)\n{\n    if (begin.size() == 0) return;\n    vector&lt;pair&lt;int, int&gt;&gt;newStart;\n    for (int i = 0; i&lt;begin.size(); i++)\n    {\n        int x = begin[i].second, y = begin[i].first;\n        if (x == finish.second && y == finish.first) return;\n        if (MAP[begin[i]] != 0) continue;\n        MAP[begin[i]]++;\n        for (int j = 0; j&lt;4; j++)\n        {\n            int xx = x + loc[j][0], yy = y + loc[j][1];\n            if (xx &gt;= 0 && xx &lt; M && yy &gt;= 0 && yy &lt; N && MAP[axis(yy, xx)] == 0 && v[yy][xx] == 0)\n            {\n                newStart.push_back(axis(yy, xx));\n                value[yy][xx] = (value[y][x] + value[yy][xx]) % 100000;\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    {\n        v.clear();\n        value.clear();\n        for (int i = 0; i&lt;N; i++)\n        {\n            vector&lt;int&gt;hi;\n            vector&lt;long long int&gt;zero;\n            for (int j = 0; j&lt;M; j++)\n            {\n                int tmp;\n                cin &gt;&gt; tmp;\n                hi.push_back(tmp);\n                zero.push_back(0);\n                MAP[axis(i, j)] = 0;\n            }\n            value.push_back(zero);\n            v.push_back(hi);\n        }\n        int x, y;\n        cin &gt;&gt; y &gt;&gt; x;\n        start.second = x;\n        start.first = y;\n        cin &gt;&gt; y &gt;&gt; x;\n        finish.second = x;\n        finish.first = y;\n        vector&lt;pair&lt;int, int&gt;&gt;tmp;\n        tmp.push_back(start);\n        value[start.first][start.second] = 1;\n        BFS(tmp);\n        cout &lt;&lt; value[finish.first][finish.second] &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge D821\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5730\u5716\u4e0a\uff0c\u7531 (Sx, Sy) \u53ea\u80fd\u4e0a\u4e0b\u5de6\u53f3\u5230\u9054 (Ex, Ey) \u7684\u6700\u77ed\u8def\u5f91\u9577 \u60f3\u5fc5\u5927\u5bb6\u90fd\u5df2\u7d93\u4e0d\u964c\u751f\u4e86\uff0c\u90a3\u9ebc\u73fe [&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":[29],"tags":[30,15,14,23,20,22,8,9],"class_list":["post-369","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-bfs","tag-long-long-int","tag-map","tag-pair","tag-20","tag-22","tag-8","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/369","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=369"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":371,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/369\/revisions\/371"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}