{"id":5337,"date":"2025-01-08T14:20:56","date_gmt":"2025-01-08T06:20:56","guid":{"rendered":"http:\/\/xinblog.ltd\/?p=5337"},"modified":"2025-01-23T14:27:25","modified_gmt":"2025-01-23T06:27:25","slug":"5337","status":"publish","type":"post","link":"http:\/\/xinblog.ltd\/?p=5337","title":{"rendered":"\u57fa\u7840\u6570\u5b66\u8bfe4-\u5f52\u7eb3"},"content":{"rendered":"<p>\u57fa\u7840\u6570\u5b66\u8bfe4-\u5f52\u7eb3<\/p>\n<p>\u6570\u5b66\u5f52\u7eb3\u6cd5\u662f\u4e00\u79cd\u7c7b\u4f3c\u73b0\u5b9e\u4e16\u754c\u4e2d\u5f52\u7eb3\u6cd5\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u6839\u636e\u7406\u8bba\u6765\u63a8\u65ad\u67d0\u4e2a\u8ba1\u7b97\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u4ee5\u68cb\u76d8\u4e0a\u653e\u9ea6\u7c92\u4e3a\u4e3e\u4f8b<\/p>\n<p>\u7b2c\u4e00\u4e2a\u843d\u5b50\u653e1\u7c92\uff0c\u7b2c\u4e8c\u4e2a\u843d\u5b50\u653e2\u7c92\uff0c\u7136\u540e\u4ee5\u540e\u6bcf\u4e00\u683c\u90fd\u591a\u4e00\u500d\u7684\u9ea6\u5b50\uff0c\u76f4\u5230\u653e\u6ee1\u3002<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u63a8\u65ad\u51fa\u4e00\u79cd\u89c4\u5f8b\u3002<\/p>\n<p>\u524dn\u4e2a\u9ea6\u7c92\u7684\u603b\u6570\u4e3a 2\u7684n\u6b21\u65b9 \u2013 1\u5462\uff1f<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u9700\u8981\u8fdb\u884c\u5f52\u7eb3\u8bc1\u660e<\/p>\n<p>\u9996\u5148\u662f\u8bc1\u660e\u57fa\u672c\u60c5\u51b5 n = 1\u65f6\u5019\u662f\u5426\u6210\u7acb\u8fd9\u4e2a\u516c\u5f0f<\/p>\n<p>\u7136\u540e\u5bf9 n = k-1\u7684\u65f6\u5019\uff0c\u63a8\u65adn=k\u7684\u60c5\u51b5\uff0c\u5e76\u9a8c\u8bc1\u5b83\u3002<\/p>\n<p>\u9996\u5148\u662fn= 1\u7684\u65f6\u5019\uff0c\u9ea6\u7c92\u5fc5\u7136\u4e3a1<\/p>\n<p>\u5176\u6b21\u662f\u6839\u636en=k-1\u7684\u65f6\u5019\uff0c\u63a8\u65adn=k\u7684\u60c5\u51b5<\/p>\n<p>\u56e0\u4e3a 2\u7684k-1\u6b21\u65b9 -1\u5bf9\u5e94\u7740 k-1\u683c<\/p>\n<p>\u90a3\u4e482\u7684k\u6b21\u65b9\u4e3a<\/p>\n<p>2\u7684k-1\u6b21\u65b9 -1 + 2\u7684k-1\u6b21\u65b9<\/p>\n<p>\u6700\u7ec8\u4e3a 2\u7684 k\u6b21\u65b9 -1<\/p>\n<p>\u6240\u4ee5\u7ed3\u679c\u6210\u7acb<\/p>\n<p>\u56e0\u4e3a\u8fd9\u4e2a\u89c4\u5f8b\u7684\u6210\u7acb\uff0c\u6240\u4ee5\u5728\u8ba1\u7b97\u67d0\u4e2a\u503c\u7684\u65f6\u5019\uff0c\u5c31\u6ca1\u5fc5\u8981\u8fdb\u884c\u9010\u6b65\u7684\u63a8\u7b97\uff0c\u6700\u7ec8\u8282\u7701\u8d44\u6e90\u3002<\/p>\n<p>\u800c\u5728\u9a8c\u8bc1\u89c4\u5f8b\u7684\u65f6\u5019\uff0c\u6211\u4eec\u751a\u81f3\u8fd8\u53ef\u4ee5\u4f7f\u7528\u7f16\u7a0b\u4e2d\u9012\u5f52\u7684\u601d\u60f3\u8fdb\u884c\u6821\u9a8c\uff0c<\/p>\n<p>\u5c31\u6bd4\u5982\u6211\u4eec\u9700\u8981\u6821\u9a8c \u7b2ck\u683c\u7684\u9ea6\u7c92\u603b\u6570\uff0c\u662f\u5426\u53ef\u4ee5\u4e0d\u65ad\u7684\u9012\u5f52\u4e0b\u53bb\uff0c\u83b7\u53d6\u4e0a\u4e00\u683c\u7684\u9ea6\u7c92\u603b\u6570\uff0c\u7136\u540e\u76f8\u52a0\u5462<\/p>\n<p>\u4e0d\u8fc7\u9700\u8981\u6ce8\u610f\uff0c\u5f53n=1\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u8fd4\u56de1\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<td>class Result {<\/p>\n<p>public long wheatNum = 0; \/\/ \u5f53\u524d\u683c\u7684\u9ea6\u7c92\u6570<\/p>\n<p>public long wheatTotalNum = 0; \/\/ \u76ee\u524d\u4e3a\u6b62\u9ea6\u7c92\u7684\u603b\u6570<\/p>\n<p>}<\/p>\n<p>public class Lesson4_2 {<\/p>\n<p>\/**<\/p>\n<p>* @Description: \u4f7f\u7528\u51fd\u6570\u7684\u9012\u5f52\uff08\u5d4c\u5957\uff09\u8c03\u7528\uff0c\u8fdb\u884c\u6570\u5b66\u5f52\u7eb3\u6cd5\u8bc1\u660e<\/p>\n<p>* @param k-\u653e\u5230\u7b2c\u51e0\u683c\uff0cresult-\u4fdd\u5b58\u5f53\u524d\u683c\u5b50\u7684\u9ea6\u7c92\u6570\u548c\u9ea6\u7c92\u603b\u6570<\/p>\n<p>* @return boolean-\u653e\u5230\u7b2ck\u683c\u65f6\u662f\u5426\u6210\u7acb<\/p>\n<p>*\/<\/p>\n<p>public static boolean prove(int k, Result result) {<\/p>\n<p>\/\/ \u8bc1\u660en = 1\u65f6\uff0c\u547d\u9898\u662f\u5426\u6210\u7acb<\/p>\n<p>if (k == 1) {<\/p>\n<p>if ((Math.pow(2, 1) &#8211; 1) == 1) {<\/p>\n<p>result.wheatNum = 1;<\/p>\n<p>result.wheatTotalNum = 1;<\/p>\n<p>return true;<\/p>\n<p>} else return false;<\/p>\n<p>}<\/p>\n<p>\/\/ \u5982\u679cn = (k-1)\u65f6\u547d\u9898\u6210\u7acb\uff0c\u8bc1\u660en = k\u65f6\u547d\u9898\u662f\u5426\u6210\u7acb<\/p>\n<p>else {<\/p>\n<p>boolean proveOfPreviousOne = prove(k &#8211; 1, result);<\/p>\n<p>result.wheatNum *= 2;<\/p>\n<p>result.wheatTotalNum += result.wheatNum;<\/p>\n<p>boolean proveOfCurrentOne = false;<\/p>\n<p>if (result.wheatTotalNum == (Math.pow(2, k) &#8211; 1)) proveOfCurrentOne = true;<\/p>\n<p>if (proveOfPreviousOne &amp;&amp; proveOfCurrentOne) return true;<\/p>\n<p>else return false;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u6837\u5229\u7528\u9012\u5f52\uff0c\u4ece\u800c\u9a8c\u8bc1\u4e86\u6570\u636e\u5f52\u7eb3\u6cd5\u7684\u63a8\u65ad\u662f\u6b63\u786e\u7684\u3002<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u8bf4\u4e86\u4e0b\u6570\u5b66\u5f52\u7eb3\u6cd5<\/p>\n<p>\u5982\u679c\u53ef\u4ee5\u5bf9\u67d0\u4e2a\u4e8b\u60c5\u8fdb\u884c\u603b\u7ed3\uff0c\u5f97\u5230\u89c4\u5f8b\uff0c\u90a3\u4e48\u5c31\u65e0\u9700\u8fed\u4ee3\u4e00\u6837\u53cd\u590d\u8ba1\u7b97\uff0c\u4ece\u800c\u8282\u7701\u5927\u91cf\u7684\u8d44\u6e90\uff0c\u63d0\u5347\u6027\u80fd\u4e86\u3002\u4e0d\u8fc7\u8fd9\u9700\u8981\u6211\u4eec\u5408\u7406\u7684\u63d0\u51fa\u5047\u8bbe\u5e76\u8fdb\u884c\u8bc1\u660e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u7840\u6570\u5b66\u8bfe4-\u5f52\u7eb3 \u6570\u5b66\u5f52\u7eb3\u6cd5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[],"_links":{"self":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5337"}],"collection":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5337"}],"version-history":[{"count":2,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5337\/revisions"}],"predecessor-version":[{"id":5339,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5337\/revisions\/5339"}],"wp:attachment":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5337"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}