{"id":1615,"date":"2020-06-01T19:39:18","date_gmt":"2020-06-01T11:39:18","guid":{"rendered":"http:\/\/bloo.heing.fun\/?p=1615"},"modified":"2020-07-12T17:55:27","modified_gmt":"2020-07-12T09:55:27","slug":"bfs-vis%e6%95%b0%e7%bb%84-%e6%9c%80%e7%9f%ad%e8%b7%af","status":"publish","type":"post","link":"https:\/\/bloo.heing.fun\/?p=1615","title":{"rendered":"bfs vis\u6570\u7ec4 \u6700\u77ed\u8def"},"content":{"rendered":"\n<p>vis\u7684\u76ee\u7684\u5176\u5b9e\u5e76\u4e0d\u662f\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u54ea\u4e9b\u8282\u70b9\uff0c\u800c\u662f\u8bb0\u5f55\u3010[\u5728\u5f53\u524d\u6b65\u9aa4] \u6216 [\u4e4b\u524d\u7684\u6b65\u9aa4]\u3011\u4e2d\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u7684\u72b6\u6001\u3002\u56e0\u4e3a\u4e4b\u524d\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u4e86\u8fd9\u4e9b\u72b6\u6001\uff0c\u800c\u4e4b\u524d\u90a3\u4e9b\u8bbf\u95ee\u7528\u7684\u6b65\u9aa4\u66f4\u5c11\uff0c\u56e0\u6b64\u4e4b\u540e\u5c31\u6ca1\u5fc5\u8981\u518d\u6b21\u8bbf\u95ee\u8fd9\u4e9b\u72b6\u6001\u4e86\u3002<\/p>\n\n\n\n<p>\u5f53\u7528bfs\u7528\u4e8e\u8bb0\u5f55\u5230\u8fbe\u67d0\u4e2a\u72b6\u6001\u7684\u6b65\u9aa4\u65f6\uff0c\u5219\u82e5\u67d0\u4e2a\u8282\u70b9 \u3010\u66fe\u7ecf\u8bbf\u95ee\u8fc7\u3011\u6216\u3010\u901a\u6b65\u9aa4\u7684\u5176\u4ed6\u72b6\u6001\u5df2\u7ecf\u5c06\u8fd9\u4e2a\u8282\u70b9\u52a0\u5165\u961f\u5217\u3011\uff0c\u5219\u4e0d\u7528\u518d\u5c06\u8fd9\u4e2a\u8282\u70b9\u52a0\u5165\u961f\u5217\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> while (!sourceq.empty()) {\n      level_count = sourceq.size();\n      while ((level_count--) > 0) {\n        auto p = sourceq.front();\n        sourceq.pop(); \n        for (int i=0; i&lt;4; i++) {\n          int subx = p.first + dx&#91;i];\n          int suby = p.second + dy&#91;i];\n          if (subx >= 0 &amp;&amp; suby >= 0 &amp;&amp; subx &lt; m &amp;&amp; suby &lt; n) {\n            if (A&#91;subx]&#91;suby] == 1) {\n              return step;\n            } else if (A&#91;subx]&#91;suby] == 0 &amp;&amp; vis2&#91;subx]&#91;suby] == 0){\n              sourceq.push({subx,suby});\n              vis2&#91;subx]&#91;suby]=1;\n            }\n          }\n        }\n      }<\/code><\/pre>\n\n\n\n<p>\u6216\u8005\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while (!sourceq.empty()) {\n      level_count = sourceq.size();\n      while ((level_count--) > 0) {\n        auto p = sourceq.front();\n        sourceq.pop();\n        if (vis2&#91;p.first]&#91;p.second] == 1) {\n          continue;\n        }\n        vis2&#91;p.first]&#91;p.second] = 1;\n        for (int i=0; i&lt;4; i++) {\n          int subx = p.first + dx&#91;i];\n          int suby = p.second + dy&#91;i];\n          if (subx >= 0 &amp;&amp; suby >= 0 &amp;&amp; subx &lt; m &amp;&amp; suby &lt; n) {\n            if (A&#91;subx]&#91;suby] == 1) {\n              return step;\n            } else if (A&#91;subx]&#91;suby] == 0){\n              sourceq.push({subx,suby});\n            }\n          }\n        }\n      }\n      step++;\n    }<\/code><\/pre>\n\n\n\n<p>\u4f46\u4e0d\u80fd\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> while (!sourceq.empty()) {\n      level_count = sourceq.size();\n      while ((level_count--) > 0) {\n        auto p = sourceq.front();\n        sourceq.pop();\n        \/\/ 1:\n        if (vis2&#91;p.first]&#91;p.second] == 1) {\n          continue;\n        }\n        vis2&#91;p.first]&#91;p.second] = 1;\n        for (int i=0; i&lt;4; i++) {\n          int subx = p.first + dx&#91;i];\n          int suby = p.second + dy&#91;i];\n          if (subx >= 0 &amp;&amp; suby >= 0 &amp;&amp; subx &lt; m &amp;&amp; suby &lt; n) {\n            if (A&#91;subx]&#91;suby] == 1) {\n              return step;\n            } else if (A&#91;subx]&#91;suby] == 0 &amp;&amp; vis2&#91;subx]&#91;suby] == 0){\n              \/\/ 2:\n              sourceq.push({subx,suby});\n              vis2&#91;subx]&#91;suby]=1;\n            }\n          }\n        }\n      }<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u505a\u7684\u8bdd\uff0c\u56e0\u4e3a2\u5904\u5df2\u7ecf\u5c06vis2[subx][suby]\u8bbe\u7f6e\u4e3a1\uff0c\u5219\u8bbf\u95ee\u8fd9\u4e2a\u8282\u70b9\u65f6\uff0c\u56e0\u4e3a1\u5904\u4ee3\u7801\u7684\u5b58\u5728\uff0c\u4f1a\u76f4\u63a5\u8df3\u8fc7\u8bbf\u95ee\u8fd9\u4e2a\u8282\u70b9\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u82e5\u6709\u591a\u4e2a\u8d77\u59cb\u72b6\u6001\u7684bfs\u51fa\u73b0\u4e86tle\uff0c\u53ef\u80fd\u7684\u539f\u56e0\u662f\uff1a\u961f\u5217\u4e2d\u7684\u8d77\u59cb\u72b6\u6001\u6709\u91cd\u590d\u7684\uff0c\u4e0d\u59a8\u8bd5\u8bd5\u6ca1\u6709\u91cd\u590d\u65f6\u53ef\u4e0d\u53ef\u4ee5\u5ea6\u8fc7\u96be\u5173\u3002\u505aleetcode::934::\u6700\u77ed\u7684\u6865\u65f6\u5c31\u56e0\u4e3a\u8fd9\u79cd\u539f\u56e0tle\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>vis\u7684\u76ee\u7684\u5176\u5b9e\u5e76\u4e0d\u662f\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u54ea\u4e9b\u8282\u70b9\uff0c\u800c\u662f\u8bb0\u5f55\u3010[\u5728\u5f53\u524d\u6b65\u9aa4] \u6216 [\u4e4b\u524d\u7684\u6b65\u9aa4]\u3011\u4e2d\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u7684\u72b6\u6001\u3002\u56e0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,36],"tags":[],"class_list":["post-1615","post","type-post","status-publish","format-standard","hentry","category-73","category-36"],"_links":{"self":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1615"}],"version-history":[{"count":6,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1615\/revisions"}],"predecessor-version":[{"id":1691,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1615\/revisions\/1691"}],"wp:attachment":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}