{"id":439027,"date":"2021-04-12T09:30:25","date_gmt":"2021-04-12T01:30:25","guid":{"rendered":"http:\/\/4563.org\/?p=439027"},"modified":"2021-04-12T09:30:25","modified_gmt":"2021-04-12T01:30:25","slug":"%e8%b0%b7%e6%ad%8c%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%9a%e6%8d%a1%e8%83%a1%e8%90%9d%e5%8d%9c","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=439027","title":{"rendered":"\u8c37\u6b4c\u9762\u8bd5\u9898\uff1a\u6361\u80e1\u841d\u535c"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8c37\u6b4c\u9762\u8bd5\u9898\uff1a\u6361\u80e1\u841d\u535c               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>\u8c37\u6b4c\u9762\u8bd5\u539f\u9898\u5730\u5740<\/h2>\n<h3>\u6837\u4f8b 1<\/h3>\n<pre><code>\u793a\u4f8b 1: \u8f93\u5165: carrot =  [[5, 7, 6, 3], [2,  4, 8, 12], [3, 5, 10, 7], [4, 16, 4, 17]] \u8f93\u51fa:  83 \u89e3\u91ca\uff1a \u8d77\u70b9\u5750\u6807\u662f(1, 1), \u79fb\u52a8\u8def\u7ebf\u662f\uff1a4 -&gt; 8 -&gt; 12 -&gt; 7 -&gt; 17 -&gt; 4 -&gt; 16 -&gt; 5 -&gt; 10 <\/code><\/pre>\n<h3>\u6837\u4f8b 2<\/h3>\n<pre><code>\u793a\u4f8b 2: \u8f93\u5165: carrot =  [[5, 3, 7, 1, 7],  [4, 6, 5, 2, 8],  [2, 1, 1, 4, 6]]  \u8f93\u51fa:   30  \u89e3\u91ca\uff1a  \u8d77\u59cb\u70b9\u662f (1, 2), \u79fb\u52a8\u8def\u7ebf\u662f\uff1a5 -&gt; 7 -&gt; 3 -&gt; 6 -&gt; 4 -&gt; 5 <\/code><\/pre>\n<h2>\u7b97\u6cd5\uff1a\u6a21\u62df<\/h2>\n<h3>\u89e3\u9898\u601d\u8def<\/h3>\n<p>\u6a21\u62df\u6361\u80e1\u841d\u535c\u7684\u8fc7\u7a0b\uff0c\u8bb0\u5f55\u7b54\u6848\u3002<\/p>\n<h2>\u590d\u6742\u5ea6\u5206\u6790<\/h2>\n<h3>\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(n*m)<\/h3>\n<p>n \u4e3a\u77e9\u9635\u957f\u5ea6\uff0cm \u4e3a\u77e9\u9635\u5bbd\u5ea6\u3002<\/p>\n<h3>\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(n*m)<\/h3>\n<p>n \u4e3a\u77e9\u9635\u957f\u5ea6\uff0cm \u4e3a\u77e9\u9635\u5bbd\u5ea6\u3002<\/p>\n<h2>\u4ee3\u7801<\/h2>\n<pre><code>public class Solution {     \/**      * @param carrot: an integer matrix      * @return: Return the number of steps that can be moved.      *\/     public int PickCarrots(int[][] carrot) {                  int row = carrot.length, col = carrot[0].length, step = 0;         int x = (row + 1) \/ 2 - 1, y = (col + 1) \/ 2 - 1;         int answer = carrot[x][y];          int[] x_dir = new int[]{0, 0, 1, -1};         int[] y_dir = new int[]{1, -1, 0, 0};         int[][] visited = new int[row][col];          for (int i = 0; i &lt; row; i++) {             for (int j = 0; j &lt; col; j++) {                 visited[i][j] = 0;             }         }         visited[x][y] = 1;         while (step &lt;= row * col - 1) {             int move_dir = -1, move_max = -1;              for (int i = 0; i &lt; 4; i++) {                 int temp_x = x + x_dir[i];                 int temp_y = y + y_dir[i];                  if (temp_x &gt;= 0 &amp;&amp; temp_x &lt; row &amp;&amp; temp_y &gt;= 0 &amp;&amp; temp_y &lt; col &amp;&amp; visited[temp_x][temp_y] == 0) {                     if (carrot[temp_x][temp_y] &gt; move_max) {                         move_max = carrot[temp_x][temp_y];                         move_dir = i;                     }                 }             }             if (move_dir == -1) {                     break;                 }                  x += x_dir[move_dir];                 y += y_dir[move_dir];                  visited[x][y] = 1;                 answer += carrot[x][y];                 step += 1;         }         return answer;     } } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5753079\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : whileFalse <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u9762\u8bd5\u9898\u8fc7\u4e8e\u7b80\u5355\u4e86\u5427\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8c37\u6b4c\u9762\u8bd5\u9898\uff1a\u6361\u80e1\u841d\u535c \u8cc7\u6df1\u5927\u4f6c :&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/439027"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=439027"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/439027\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=439027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=439027"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=439027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}