{"id":1529,"date":"2024-06-20T11:53:16","date_gmt":"2024-06-20T03:53:16","guid":{"rendered":"https:\/\/aoofoo.com\/?p=1529"},"modified":"2025-02-20T16:21:55","modified_gmt":"2025-02-20T08:21:55","slug":"1-2-%e7%ae%97%e6%b3%95%e6%97%b6%e9%97%b4%e5%a4%8d%e6%9d%82%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/aoofoo.com\/index.php\/2024\/06\/20\/1-2-%e7%ae%97%e6%b3%95%e6%97%b6%e9%97%b4%e5%a4%8d%e6%9d%82%e5%ba%a6\/","title":{"rendered":"1.2 \u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6"},"content":{"rendered":"<h2>\u65f6\u95f4\u590d\u6742\u5ea6<\/h2>\n<p>\u7b97\u6cd5 + \u6570\u636e\u7ed3\u6784 = \u7a0b\u5e8f\u3002<\/p>\n<p>\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u662f\u606f\u606f\u76f8\u5173\u7684\uff0c\u4ed6\u4eec\u4fe9\u662f\u5206\u4e0d\u5f00\u7684\uff0c\u7b97\u6cd5\u8981\u6ee1\u8db35\u4e2a\u91cd\u8981\u7279\u6027\uff1a<\/p>\n<p>\u6709\u7a77\u6027\u3001\u786e\u5b9a\u6027\u3001\u53ef\u884c\u6027\u3001\u8f93\u5165\u3001\u8f93\u51fa\u3002\u8fd9\u4e94\u4e2a\u91cd\u8981\u7279\u6027\uff0c\u4f46\u6211\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u6ca1\u6709\u4ec0\u4e48\u7528\uff0c\u6982\u5ff5\u4e0a\u7684\u4e1c\u897f\u5f80\u5f80\u5047\u5927\u7a7a\u3002<\/p>\n<p>\u7b97\u6cd5\u7684\u6267\u884c\u6548\u7387\uff0c\u4e5f\u79f0\u4f5c<strong>\u65f6\u95f4\u590d\u6742\u5ea6O<\/strong>\uff0cT(n) = O(f(n)),\u968f\u7740\u95ee\u9898\u89c4\u6a21n\u7684\u589e\u5927\uff0c\u7b97\u6cd5\u6267\u884c\u65f6\u95f4\u548c\u589e\u957f\u7387\u548cf(n)\u589e\u957f\u7387\u6210\u6b63\u6bd4\u3002<\/p>\n<p>\u7a0b\u5e8f\u8fd0\u884c\u7684\u603b\u65f6\u95f4\u4e3b\u8981\u548c\u4e24\u70b9\u6709\u5173\uff0c\u4e00\u662f\u6267\u884c\u6bcf\u6761\u8bed\u53e5\u7684\u8017\u65f6\uff0c\u4e8c\u662f\u6bcf\u6761\u8bed\u53e5\u7684\u6267\u884c\u9891\u7387\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u8fd9\u4e2afor\u5faa\u73af\u6267\u884c\u4e86\u591a\u5c11\u6b21\uff1f<\/p>\n<pre class=\"corepress-code-pre\"><code>for(int i=1; i&lt;=n; i++)\r\n{\r\n\r\n}<\/code><\/pre>\n<p>\u6211\u4eec\u80fd\u8f7b\u6613\u5730\u77e5\u9053\u6267\u884c\u4e86N+1\u6b21\uff0c\u90a3\u4e48\u4e0b\u9762\u7684for\u5faa\u73af\u6267\u884c\u4e86\u591a\u5c11\u6b21\uff1f<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"corepress-code-pre\"><code>for(int i=1; i&lt;=n; i++) \/\/n+1\u6b21\r\n{\r\n  for(int j = 1; j&lt;=n;j++) \/\/n*\uff08n+1\uff09\u6b21\r\n  {\r\n   c[i][j] = 0; \/\/ n*n\u6b21\r\n  for(int k=1;k&lt;=n; k++) \/\/n*n*\uff08n+1\uff09\u6b21\r\n  {\r\n  c[i][j] = c[i][j] + a[i][k]*b[k][j]; \/\/ n*n*n\u6b21\r\n  }\r\n  }\r\n }<\/code><\/pre>\n<p>\u6211\u4eec\u77e5\u9053\u7b2c\u4e00\u5c42for\u5faa\u73af\uff0c\u80fd\u591f\u5b9e\u9645\u6267\u884c\u7b2c\u4e8c\u5c42for\u5faa\u73af\u7684\u6b21\u6570\u662fn\u6b21\uff08\u7b2cn+1\u6b21\u53ea\u5224\u65ad\u800c\u4e0d\u8fdb\u5165\u7b2c\u4e8c\u5c42for\u5faa\u73af\uff09\uff0c\u6240\u4ee5\u7b2c\u4e8c\u5c42for\u5faa\u73af\u6267\u884c\u7684\u6b21\u6570\u5e94\u8be5\u662fn*\uff08n+1\uff09\u6b21\uff0c\u540c\u7406\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u5176\u4ed6\u8bed\u53e5\u7684\u6267\u884c\u6b21\u6570\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u6211\u4eec\u628a\u6240\u6709\u7684\u6b21\u6570\u52a0\u5230\u4e00\u8d77\uff0c\u5c31\u662ff(n)\uff0cf(n)= 2n\u00b3+3n\u00b2+2n+1\u3002<\/p>\n<p>\u8fd9\u4e2af(n)\u5c31\u662f\u6211\u4eec\u8981\u7684\u6267\u884c\u6548\u7387\u5417\uff1f\u4e5f\u4e0d\u662f\uff0c\u4ed6\u8fd8\u662f\u6709\u4e00\u4e2a\u81ea\u5df1\u7684\u5957\u8def\u548c\u89c4\u5219\u7684\uff1a<\/p>\n<p>\u90a3\u5c31\u662f\uff0c\u5728\u8ba1\u7b97\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u65f6\uff0c<strong>\u53ef\u4ee5\u5ffd\u7565\u6240\u6709\u4f4e\u6b21\u5e42\u548c\u6700\u9ad8\u6b21\u5e42\u7684\u7cfb\u6570<\/strong>\uff0c\u53ef\u4ee5\u7b80\u5316\u7b97\u6cd5\u5206\u6790\u3002<\/p>\n<p>\u6240\u4ee5f(n)= 2n\u00b3+3n\u00b2+2n+1\u5c31\u88ab\u7b80\u5316\u6210\u4e86n\u00b3\uff0c\u5373T(n) = O(n\u00b3)\u3002<\/p>\n<p>\u518d\u6df1\u5165\u601d\u8003\u4e00\u4e0b\uff0c\u5982\u679c\u4f60\u7684\u7b97\u6cd5\u4e2d\u7684\u5faa\u73af\u662f\u4e00\u4e2a\u786e\u5b9a\u7684\u5e38\u6570\u7684\u8bdd\uff0c\u90a3\u4e48\u4e0d\u8bba\u8fd9\u4e2a\u5e38\u6570\u6709\u591a\u5927\uff0c\u90a3\u4e48\u4ed6\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u6052\u4e3aO(1)\u3002<\/p>\n<h2>\u7a7a\u95f4\u590d\u6742\u5ea6<\/h2>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3b\u8981\u7528\u6765\u63cf\u8ff0\u67d0\u4e2a\u7b97\u6cd5\u5bf9\u5e94\u7684\u7a0b\u5e8f\u60f3\u5728\u8ba1\u7b97\u673a\u4e0a\u6267\u884c\uff0c\u9664\u4e86\u7528\u6765\u5b58\u50a8\u4ee3\u7801\u548c\u8f93\u5165\u6570\u636e\u7684\u5185\u5b58\u7a7a\u95f4\u5916\uff0c\u8fd8\u989d\u5916\u9700\u8981\u7684\u7a7a\u95f4\uff0cS(n) = O(f(n))\u3002<\/p>\n<p>\u4e0d\u8fc7\u6211\u4eec\u90fd\u662f\u4ee5\u65f6\u95f4\u590d\u6742\u5ea6\u6765\u4f5c\u4e3a\u5bf9\u7b97\u6cd5\u4f18\u52a3\u7684\u8861\u91cf\u6307\u6807\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u5927\u591a\u6570\u65f6\u5019\u4e0d\u7528\u5728\u610f\uff0c\u5f53\u7136\uff0c\u540e\u7eed\u6211\u4eec\u4f1a\u4f7f\u7528MCU\uff0cMCU\u7684\u7a7a\u95f4\u5f80\u5f80\u5e76\u4e0d\u662f\u90a3\u4e48\u5145\u8db3\uff0c\u503c\u5f97\u6ce8\u610f\u4e00\u4e0b\u3002<\/p>\n<h2>\u7ec3\u4e60<\/h2>\n<p>\u601d\u8003\u4e0b\u9762\u7684\u4ee3\u7801\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u591a\u5c11\uff1f<\/p>\n<pre class=\"corepress-code-pre\"><code>for(int i = 1; i&lt;=n;i = i*2)\r\n{\r\n x++\uff1b\r\n s = 0;\r\n}\r\n<\/code><\/pre>\n<div class=\"sc-collapse\"><div class=\"sc-collapse__header\"><svg class=\"sc-collapse__arrow\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><polyline points=\"6 9 12 15 18 9\"\/><\/svg>\u89e3\u6790\u70b9\u51fb\u67e5\u770b<\/div><div class=\"sc-collapse__body\"><div class=\"sc-collapse__content\"><\/p>\n<p>\u6211\u4eec\u5148\u627e\u89c4\u5f8b\uff0c\u5982\u679c\u6267\u884c1\u6b21\uff0ci\u7684\u503c\u662f\u591a\u5c11\uff0c\u5982\u679c\u6267\u884c2\u6b21\uff0ci\u7684\u503c\u662f\u591a\u5c11\uff0c&#8230;\uff0c\u5982\u679c\u6267\u884ct\u6b21\uff0ci\u7684\u503c\u662f\u591a\u5c11\uff1f<\/p>\n<p>\u53ef\u4ee5\u53d1\u73b0\uff0c\u7b2c\u4e00\u6b21 i = 1\uff0c\u7b2c\u4e8c\u6b21 i = 2\uff0c\u7b2c\u4e09\u6b21 i = 2\u00b2\uff0c&#8230;\uff0c\u7b2ct\u6b21\uff0ci=2\u7684t-1\u6b21\u5e42\u3002<\/p>\n<p>\u5047\u8bbe\u7b2ct\u6b21\uff0c\u521a\u597di&gt;n\uff0c\u90a3\u4e48\u5faa\u73af\u4e0d\u7ee7\u7eed\uff0c\u90a3\u4e48\u53ef\u4ee5\u786e\u5b9a2\u7684t-1\u6b21\u5e42\u5927\u4e8en\uff0c\u53ef\u4ee5\u5f97\u5230\u4e0b\u9762\u7684\u8ba1\u7b97\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1530\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2025\/02\/\u5c4f\u5e55\u622a\u56fe-2025-02-16-115134.png\" alt=\"\" width=\"161\" height=\"193\" \/><\/p>\n<p><\/div><\/div><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65f6\u95f4\u590d\u6742\u5ea6 \u7b97\u6cd5 + \u6570\u636e\u7ed3\u6784 = \u7a0b\u5e8f\u3002 \u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u662f\u606f\u606f\u76f8\u5173\u7684\uff0c\u4ed6\u4eec\u4fe9\u662f\u5206\u4e0d\u5f00\u7684\uff0c\u7b97\u6cd5\u8981\u6ee1\u8db35\u4e2a\u91cd\u8981\u7279 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1529","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/1529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/comments?post=1529"}],"version-history":[{"count":6,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/1529\/revisions"}],"predecessor-version":[{"id":1539,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/1529\/revisions\/1539"}],"wp:attachment":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/media?parent=1529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/categories?post=1529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/tags?post=1529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}