{"id":150153,"date":"2020-09-02T18:48:20","date_gmt":"2020-09-02T10:48:20","guid":{"rendered":"http:\/\/4563.org\/?p=150153"},"modified":"2020-09-02T18:48:20","modified_gmt":"2020-09-02T10:48:20","slug":"%e5%88%9a%e5%81%9a%e5%88%b0%e7%9a%84%e7%99%be%e5%ba%a6%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%9a%e7%a5%96%e7%8e%9b%e6%b8%b8%e6%88%8f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=150153","title":{"rendered":"\u521a\u505a\u5230\u7684\u767e\u5ea6\u9762\u8bd5\u9898\uff1a\u7956\u739b\u6e38\u620f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u521a\u505a\u5230\u7684\u767e\u5ea6\u9762\u8bd5\u9898\uff1a\u7956\u739b\u6e38\u620f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 17<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7956\u739b\u6e38\u620f\u3002<\/p>\n<p>\u4e00\u884c\u7403\u653e\u5728\u684c\u9762\u4e0a\uff0c\u7403\u88ab\u6d82\u4e0a\u4e86\u7ea2\uff08 R \uff09\u3001\u9ec4\uff08 Y \uff09\u3001\u84dd\uff08 B \uff09\u3001\u7eff\uff08 G \uff09\u548c\u767d\uff08 W \uff09\u8fd9\u4e48\u51e0\u79cd\u989c\u8272\uff0c\u540c\u65f6\u4f60\u4e5f\u62e5\u6709\u51e0\u4e2a\u7403\u3002<\/p>\n<p>\u6bcf\u4e00\u6b21\uff0c\u4ece\u4f60\u62e5\u6709\u7684\u7403\u5f53\u4e2d\u62ff\u51fa\u4e00\u4e2a\uff0c\u63d2\u5165\u5230\u5f53\u524d\u884c\u5f53\u4e2d\uff08\u5305\u62ec\u6700\u5de6\u8fb9\u548c\u6700\u53f3\u8fb9\uff09\u3002\u7136\u540e\uff0c\u5982\u679c\u6709\u4e09\u4e2a\u6216\u66f4\u591a\u7684\u540c\u8272\u7403\u6328\u5728\u4e00\u8d77\uff0c\u7136\u540e\u5c31\u6d88\u9664\u8fd9\u51e0\u4e2a\u7403\u3002\u4e00\u76f4\u8fd9\u4e48\u505a\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u7684\u7403\u53ef\u4ee5\u6d88\u9664\u3002 \u627e\u5230\u6700\u5c11\u7684\u9700\u8981\u63d2\u5165\u7684\u7403\u7684\u6570\u91cf\uff0c\u4f7f\u5f97\u6240\u6709\u7684\u7403\u90fd\u53ef\u4ee5\u88ab\u5220\u9664\u3002\u5982\u679c\u4e0d\u80fd\u5220\u9664\u6240\u6709\u7684\u7403\uff0c\u90a3\u4e48\u5c31\u8fd4\u56de-1 \u3002<\/p>\n<ul>\n<li>\u521d\u59cb\u7684\u884c\u4e0d\u4f1a\u62e5\u6709\u4e09\u4e2a\u53ca\u4ee5\u4e0a\u7684\u8fde\u7eed\u7684\u540c\u8272\u7403\u3002<\/li>\n<li>\u884c\u4e2d\u7684\u7403\u7684\u6570\u91cf\u4e0d\u4f1a\u8d85\u8fc7 20\uff0c\u7528\u540d\u4e3a&#8221;borad&#8221;\u7684\u8f93\u5165\u5b57\u7b26\u4e32\u8868\u793a\u3002<\/li>\n<li>\u4f60\u62e5\u6709\u7684\u7403\u4e0d\u4f1a\u8d85\u8fc7 5 \u4e2a\uff0c\u7528\u540d\u4e3a&#8221;hand&#8221;\u7684\u8f93\u5165\u5b57\u7b26\u4e32\u8868\u793a\u3002<\/li>\n<li>\u8f93\u5165\u5b57\u7b26\u4e32\u90fd\u975e\u7a7a\uff0c\u800c\u4e14\u4ec5\u5305\u542b\u5b57\u7b26 &#8216;R&#8217;,&#8217;Y&#8217;,&#8217;B&#8217;,&#8217;G&#8217;,&#8217;W&#8217;\u3002<\/li>\n<\/ul>\n<p>\u70b9\u8fd9\u91cc\u53ef\u4ee5\u5728\u7ebf\u505a\u9898<\/p>\n<h2>\u6837\u4f8b 1:<\/h2>\n<pre><code>\u8f93\u5165: \"WRRBBW\", \"RB\" \u8f93\u51fa: -1 \u89e3\u91ca: WRRBBW -&gt; WRR[R]BBW -&gt; WBBW -&gt; WBB[B]W -&gt; WW <\/code><\/pre>\n<h2>\u6837\u4f8b 2:<\/h2>\n<pre><code>\u8f93\u5165: \"WWRRBBWW\", \"WRBRW\" \u8f93\u51fa: 2 \u89e3\u91ca: WWRRBBWW -&gt; WWRR[R]BBWW -&gt; WWBBWW -&gt; WWBB[B]WW -&gt; WWWW -&gt; empty <\/code><\/pre>\n<h2>\u6837\u4f8b 3:<\/h2>\n<pre><code>\u8f93\u5165:\"G\", \"GGGGG\" \u8f93\u51fa: 2 \u89e3\u91ca: G -&gt; G[G] -&gt; GG[G] -&gt; empty  <\/code><\/pre>\n<h2>\u6837\u4f8b 4:<\/h2>\n<pre><code>\u8f93\u5165: \"RBYYBBRRB\", \"YRBGB\" \u8f93\u51fa: 3 \u89e3\u91ca: RBYYBBRRB -&gt; RBYY[Y]BBRRB -&gt; RBBBRRB -&gt; RRRB -&gt; B -&gt; B[B] -&gt; BB[B] -&gt; empty  <\/code><\/pre>\n<h1>[\u9898\u89e3]<\/h1>\n<p> <\/p>\n<p>\u8003\u70b9\uff1a<\/p>\n<ul>\n<li>\u641c\u7d22 \u9898\u89e3\uff1a\u57fa\u672c\u601d\u8def\u5c31\u662f\u641c\u7d22\uff0cc \u6570\u7ec4\u7edf\u8ba1\u81ea\u5df1\u5404\u7c7b\u7403\u7684\u6570\u91cf\uff0c\u5bf9 board \u8fdb\u884c\u904d\u5386\uff0c\u7136\u540e j \u4fdd\u5b58\u4e00\u6bb5\u7684\u8d77\u70b9\uff0ci \u5411\u540e\u79fb\u52a8\u81f3\u51fa\u73b0\u4e0d\u540c\u7684\u7403\uff0c\u7136\u540e\u5bf9\u8fd9\u6bb5\u957f\u5ea6\u5224\u65ad\uff0c\u6839\u636e inc \u5224\u65ad\u9700\u8981\u51e0\u4e2a\u7403\u63d2\u5165\uff0c\u5bf9\u5e94\u7684\u7403\u6570\u91cf\u51cf\u5c11\uff0c\u7136\u540e\u622a\u53d6\u8d77\u70b9\u81f3 j \u7684\u533a\u95f4\u548c i \u81f3\u533a\u95f4\u7ec8\u70b9\u7684\u4e24\u6bb5\u62fc\u63a5\uff0c\u7ee7\u7eed\u641c\u7d22\u5373\u53ef\u3002<\/li>\n<\/ul>\n<pre><code>public class Solution {     \/**      * @param board: the given board      * @param hand: the balls in your hand      * @return: the minimal balls you have to insert to remove all the balls on the table      *\/     private int aux(String s, int[] c){         if(\"\".equals(s)) {             return 0;         }         int res = 2 * s.length() + 1;          for(int i = 0; i &lt; s.length();){             int j = i++;    \/\/j \u4fdd\u5b58\u8d77\u70b9             while(i &lt; s.length() &amp;&amp; s.charAt(i) == s.charAt(j)) {                 i++;             }             int inc = 3 - i + j;  \/\/3-(i-j) \u5224\u65ad\u6d88\u9664\u9700\u8981\u51e0\u4e2a\u7403             if(c[s.charAt(j)] &gt;= inc){  \/\/\u5982\u679c\u6570\u91cf\u8db3\u591f                 int used = inc &lt;= 0 ? 0 : inc;    \/\/\u5982\u679c inc&lt;=0\uff0c\u4e0d\u9700\u8981                 c[s.charAt(j)] -= used;    \/\/\u7528\u6389 s[j]                 int temp = aux(s.substring(0, j) + s.substring(i), c);  \/\/\u53bb\u9664 j \u81f3 i \u7684\u4e00\u6bb5\u7ee7\u7eed\u641c\u7d22                 if(temp &gt;= 0) {                     res = Math.min(res, used + temp);                 }                 c[s.charAt(j)] += used; \/\/\u641c\u7d22\u5b8c\u6210\u540e\u8865\u5145\u7403\u7684\u6570\u91cf             }         }         return res == 2 * s.length() + 1 ? -1 : res;     }          public int findMinStep(String board, String hand) {         \/\/ Write your code here         int[] c = new int[128];         for(char x : hand.toCharArray()){             c[x]++;         }         return  aux(board, c);     } } <\/code><\/pre>\n<p>\u66f4\u591a\u9898\u89e3\u53c2\u89c1<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u521a\u505a\u5230\u7684\u767e\u5ea6\u9762\u8bd5\u9898\uff1a\u7956\u739b\u6e38\u620f \u8cc7\u6df1&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\/150153"}],"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=150153"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/150153\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150153"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}