{"id":273,"date":"2010-09-19T23:24:06","date_gmt":"2010-09-20T03:24:06","guid":{"rendered":"http:\/\/hw.minilinux.net\/?p=273"},"modified":"2010-10-26T12:37:49","modified_gmt":"2010-10-26T16:37:49","slug":"%e6%af%8f%e6%97%a55%e9%a2%98-0919","status":"publish","type":"post","link":"https:\/\/hw.minilinux.net\/?p=273","title":{"rendered":"\u6bcf\u65e55\u9898&#8211;0919"},"content":{"rendered":"<p>1. longest increasing sequence<br \/>\n\u610f\u601d\u5c31\u662f\u7ed9\u4f60\u4e00\u4e2a\u6570\u5217 \u627e\u51fa\u6700\u957f\u8fde\u7eed\u5b57\u4e32\u7684\u957f\u5ea6<br \/>\n\u6bd4\u5982 -1 2 -2 5 3 9 8 10<br \/>\n\u7b54\u6848 \u662f5, -1 2 3 9 10<\/p>\n<p>I DP,  \u7528S[i] \u4ee3\u8868 \u4ee5\u6570\u7ec4\u5143\u7d20a[i]\u7ed3\u5c3e\u7684\u6700\u957fsequence\u7684\u957f\u5ea6, \u5f88\u597d\u5217\u51fa \u89c4\u5f8b\u8868\u8fbe\u5f0f, Time Complexity O(N^2), \u8fd9\u4e2a\u65b9\u6cd5\u867d\u7136\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u662f\u6700\u4f18, \u4f46\u662f\u597d\u5904\u662f \u6211\u4eec\u53ef\u4ee5\u9006\u5411\u56de\u53bb\u6253\u5370\u51fa \u8fd9\u4e2alongest increasing sequence\u7684\u5143\u7d20\u5206\u522b\u662f\u4ec0\u4e48, \u8fd9\u4e5f\u662f\u6211\u4e0b\u9762\u8981\u4ecb\u7ecd\u7684\u65b9\u6cd5\u6240\u4e0d\u80fd\u505a\u5230\u7684.<\/p>\n<p>II \u5982\u679c\u8003\u8651\u7528 S[i] \u4ee3\u8868 \u957f\u5ea6\u4e3a i \u7684 increasing sequence\u7684 \u7ed3\u5c3e\u5143\u7d20 \u7684\u6700\u5c0f\u503c, \u90a3\u4e48\u6211\u4eec\u77e5\u9053\u80af\u5b9a\u6709 S[k+1]>S[k]>S[k-1]>&#8230;.S[0], \u6240\u4ee5\u6bcf\u6b21\u6211\u4eec\u6709\u65b0\u7684\u5143\u7d20\u63d2\u5165, \u5176\u5b9e\u90fd\u76f8\u5f53\u4e8e\u63d2\u5165\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4, \u90a3\u4e48\u5c31\u7528binary search\u627e\u5230\u8981\u63d2\u5165\u7684\u90a3\u4e2aindex\u5c31\u597d\u4e86.  \u6240\u4ee5\u65f6\u95f4\u590d\u6742\u5ea6\u662f O(nlogn)<\/p>\n<p>\u4e00\u822c\u5bf9\u4e8e\u8fd9\u4e2a\u6570\u7ec4\u7684\u8d4b\u521d\u503c\u90fd\u662f\u8d4b\u4e00\u4e2a\u5f88\u5927\u7684\u503c, \u6240\u4ee5\u5176\u5b9e\u6bcf\u6b21\u4e0d\u662f\u8981\u5bf9\u6574\u4e2a\u957f\u5ea6n\u8fdb\u884c binary search, \u53ea\u8981\u5bf9\u4f60\u4fee\u6539\u5230\u7684\u6700\u5927index\u4e4b\u5185\u7684\u6570\u7ec4\u8fdb\u884cbinary search\u5c31\u597d\u4e86, \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u8ba1\u7b97\u5176\u5b9e\u662f log 1+ log 2+&#8230;.log n = log(n!), which is O(nlog), \u8fd9\u6837\u5176\u5b9e\u76f8\u5f53\u4e8e\u628a\u5e38\u6570\u9879\u964d\u4f4e\u4e86.<\/p>\n<p>2. \u7ed9\u4f60\u4e00\u4e2aint \u6570, \u627e\u51fa\u5176\u4e2d bit pattern \u4e2d&#8217;1&#8217;\u7684\u4e2a\u6570<br \/>\na. count = count + n>>1;<br \/>\n    n = n>>1;    \u548cint \u7684 \u603bbit\u6570\u76ee\u7ebf\u6027\u5173\u7cfb<\/p>\n<p>b. for( ; n; n = n&#038;(n-1))<br \/>\n      count ++;  \u548c\u8fd9\u4e2a\u6570\u4e2d\u6709\u591a\u5c11\u4e2a&#8217;1&#8242; \u7ebf\u6027\u5173\u7cfb<\/p>\n<p>3. Reverse a single linked-list<\/p>\n<p>4. Reverse a double linked-list<\/p>\n<p>5. How to implement using memory without initialization<\/p>\n<p>\u7f16\u7a0b\u73e0\u7391column1 exercise 8<br \/>\n\u5177\u4f53\u7684\u5e94\u7528\u662f \u7528\u7a7a\u95f4\u6765\u6362\u65f6\u95f4 <\/p>\n<p>FYI:<br \/>\n\u6bcf\u65e55\u9898 is back, and I will try my best to keep on, thanks <\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. longest increasing sequence \u610f\u601d\u5c31\u662f\u7ed9\u4f60\u4e00\u4e2a\u6570\u5217 \u627e\u51fa\u6700\u957f\u8fde\u7eed\u5b57\u4e32\u7684\u957f\u5ea6 \u6bd4\u5982 -1 2 -2 5 3 9 8 10 \u7b54\u6848 \u662f5, -1 2 3 9 10 I DP, \u7528S[i] \u4ee3\u8868 \u4ee5\u6570\u7ec4\u5143\u7d20a[i]\u7ed3\u5c3e\u7684\u6700\u957fsequence\u7684\u957f\u5ea6, \u5f88\u597d\u5217\u51fa \u89c4\u5f8b\u8868\u8fbe\u5f0f, Time Complexity O(N^2), \u8fd9\u4e2a\u65b9\u6cd5\u867d\u7136\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u662f\u6700\u4f18, \u4f46\u662f\u597d\u5904\u662f \u6211\u4eec\u53ef\u4ee5\u9006\u5411\u56de\u53bb\u6253\u5370\u51fa \u8fd9\u4e2alongest increasing sequence\u7684\u5143\u7d20\u5206\u522b\u662f\u4ec0\u4e48, \u8fd9\u4e5f\u662f\u6211\u4e0b\u9762\u8981\u4ecb\u7ecd\u7684\u65b9\u6cd5\u6240\u4e0d\u80fd\u505a\u5230\u7684. II \u5982\u679c\u8003\u8651\u7528 S[i] \u4ee3\u8868 \u957f\u5ea6\u4e3a i \u7684 increasing sequence\u7684 \u7ed3\u5c3e\u5143\u7d20 \u7684\u6700\u5c0f\u503c, \u90a3\u4e48\u6211\u4eec\u77e5\u9053\u80af\u5b9a\u6709 S[k+1]>S[k]>S[k-1]>&#8230;.S[0], \u6240\u4ee5\u6bcf\u6b21\u6211\u4eec\u6709\u65b0\u7684\u5143\u7d20\u63d2\u5165, \u5176\u5b9e\u90fd\u76f8\u5f53\u4e8e\u63d2\u5165\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4, \u90a3\u4e48\u5c31\u7528binary &hellip; <a href=\"https:\/\/hw.minilinux.net\/?p=273\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u6bcf\u65e55\u9898&#8211;0919&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-273","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273"}],"version-history":[{"count":5,"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions"}],"predecessor-version":[{"id":275,"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions\/275"}],"wp:attachment":[{"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hw.minilinux.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}