{"id":479,"date":"2010-10-24T21:03:46","date_gmt":"2010-10-24T13:03:46","guid":{"rendered":"http:\/\/comzyh.tk\/blog\/?p=479"},"modified":"2015-10-24T16:44:27","modified_gmt":"2015-10-24T08:44:27","slug":"%e5%9c%a8%e4%b8%80%e7%bb%b4%e6%95%b0%e7%bb%84%e4%b8%ad%e4%bb%a5%e5%ae%8c%e5%85%a8%e4%ba%8c%e5%8f%89%e6%a0%91%e6%96%b9%e5%bc%8f%e5%ad%98%e5%82%a8%e7%ba%bf%e6%ae%b5%e6%a0%91%e7%9a%84%e7%a9%ba%e9%97%b4","status":"publish","type":"post","link":"https:\/\/comzyh.com\/blog\/archives\/479\/","title":{"rendered":"\u5728\u4e00\u7ef4\u6570\u7ec4\u4e2d\u4ee5\u5b8c\u5168\u4e8c\u53c9\u6811\u65b9\u5f0f\u5b58\u50a8\u7ebf\u6bb5\u6811\u7684\u7a7a\u95f4\u5206\u6790"},"content":{"rendered":"<p>\u6211\u4eec\u5927\u5bb6\u5b58\u50a8\u7ebf\u6bb5\u6811\u7684\u65b9\u5f0f\u65e0\u975e\u4e24\u79cd\uff1a<\/p>\n<ol>\n<li>\u4e8c\u53c9\u94fe\u8868<\/li>\n<li>\u4e00\u7ef4\u6570\u7ec4\u5b8c\u5168\u4e8c\u53c9\u6811<\/li>\n<\/ol>\n<p>\u4e8c\u53c9\u94fe\u8868\u4f18\u70b9\u662f\u8282\u7701\u7a7a\u95f4,\u7f3a\u70b9\u662f\u7f16\u7a0b\u590d\u6742\u5ea6\u5927,\u6267\u884c\u6548\u7387\u8f83\u4f4e,\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a2N<\/p>\n<p>\u5728\u4e00\u7ef4\u6570\u7ec4\u4ee5\u5b8c\u5168\u4e8c\u53c9\u6811\u65b9\u5f0f\u5b58\u50a8\u7ebf\u6bb5\u6811\u7684\u7f16\u7a0b\u590d\u6742\u5ea6\u5c0f,\u6267\u884c\u6548\u7387\u8f83\u9ad8,\u4f46\u6d6a\u8d39\u7a7a\u95f4<br \/>\n\u957f\u671f\u4ee5\u6765,\u6211\u548c\u6211\u6821\u7684OIer\u4e00\u76f4\u4e0d\u77e5\u4ee5\u4e00\u7ef4\u65b9\u5f0f\u5b58\u50a8\u7ebf\u6bb5\u6811\u5230\u5e95\u9700\u8981\u5f00\u591a\u5927\u7684\u6570\u7ec4.\u4eca\u5929\u6b63\u597d\u6709\u4e9b\u95f2\u6687\u7684\u65f6\u95f4,\u5199\u4e86\u4e2a\u5c0f\u7a0b\u5e8f,\u5206\u6790\u4e86\u4e0b\u4e00\u7ef4\u7ebf\u6bb5\u6811\u5728\u4e00\u7ef4\u65b9\u5f0f\u5b58\u50a8\u4e0b\u5230\u5e95\u9700\u8981\u5360\u7528\u591a\u5c11\u7a7a\u95f4.\u7ecf\u672c\u6587\u6240\u8ff0\u65b9\u5f0f\u8ba1\u7b97\u7ea6\u4e3a<span style=\"color: #ff0000;\">4N<\/span><\/p>\n<p><!--more--><\/p>\n<p>\u5148\u6765\u8865\u4e60\u4e00\u4e0b\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u76f8\u5173\u77e5\u8bc6:<br \/>\n\u5b8c\u5168\u4e8c\u53c9\u6811\u5728\u4e00\u7ef4\u6570\u7ec4\u4e2d\u8fd9\u6837\u8868\u793a:\u6839\u8282\u70b9\u4e3a1,\u5176\u5de6\u5b50\u6811\u4e3a2,\u53f3\u5b50\u6811\u4e3a3.<br \/>\n\u6839\u8282\u70b9\u4e3aN,\u5176\u5de6\u5b69\u5b50\u4e3a2N,\u53f3\u5b69\u5b50\u4e3a2N+1<br \/>\n\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u53ef\u53c2\u8003<a href=\"\/\/comzyh.com\/blog\/archives\/452\" target=\"_blank\">\u6211\u7684\u4e00\u7bc7\u9898\u89e3<\/a>,\u8fd9\u91cc\u4f7f\u7528\u7684\u5c31\u662f\u5b8c\u5168\u4e8c\u53c9\u6811\u65b9\u5f0f<\/p>\n<p>\u50cf\u7ebf\u6bb5\u6811\u8fd9\u6837\u533a\u95f4\u957f\u5ea6\u5e76\u4e0d\u4e00\u5b9a\u662f\\( 2^{n}\\)\u7684\u4e8c\u53c9\u6811,\u5176\u5360\u7528\u7a7a\u95f4\u4e3a 2\u7684(\u6700\u6df1\u7ebf\u6bb5\u7684\u6df1\u5ea6)\u6b21\u5e42,\u5c31\u7ed9\u7ebf\u6bb5\u6811\u7684\u7a7a\u95f4\u5360\u7528\u9020\u6210\u4e86\u5f88\u5927\u7684\u4e0d\u786e\u5b9a\u6027.\u5728\u6211\u4eec\u5b66\u6821,\u5173\u4e8e\u7ebf\u6bb5\u6811\u7684\u7a7a\u95f4\u5360\u7528,\u8bf4\u6cd5\u5927\u81f4\u6709\u4ee5\u4e0b\u51e0\u79cd<\/p>\n<ul>\n<li>\u6781\u7aef\u4fdd\u5b88\u7684:10N<\/li>\n<li>\u4fdd\u5b88(\u6211):5N<\/li>\n<li>\u4e50\u89c2:3N<\/li>\n<li>\u6781\u4e50\u89c2:2N<\/li>\n<\/ul>\n<p>\u7136\u800c\u5927\u5bb6\u5199\u7684\u662f\u540e\u5927\u90e8\u5206\u90fd\u662f\u5c3d\u91cf\u591a\u5f00,\u5bf9\u4e8e\u5176\u7a7a\u95f4\u5360\u7528\u4e00\u76f4\u6ca1\u6709\u5b9a\u8bba,\u73b0\u5728\u6211\u6765\u7ed9\u4e2a\u5b9a\u8bba:<\/p>\n<p>\u5148\u4e0a\u4e00\u5e45\u56fe:<\/p>\n<figure id=\"attachment_485\" aria-describedby=\"caption-attachment-485\" style=\"width: 679px\" class=\"wp-caption alignnone\"><a rel=\"attachment wp-att-485\" href=\"\/\/comzyh.com\/blog\/archives\/479\/segmenttreecount\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"485\" data-permalink=\"https:\/\/comzyh.com\/blog\/archives\/479\/segmenttreecount\/\" data-orig-file=\"https:\/\/i0.wp.com\/comzyh.com\/upload\/wordpress\/\/2010\/10\/SegmentTreeCount.png?fit=679%2C845&amp;ssl=1\" data-orig-size=\"679,845\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"SegmentTreeCount\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;\u5b8c\u5168\u4e8c\u53c9\u6811\u65b9\u5f0f\u5b58\u50a8\u7ebf\u6bb5\u6811\u7684\u7a7a\u95f4\u5360\u7528&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/comzyh.com\/upload\/wordpress\/\/2010\/10\/SegmentTreeCount.png?fit=679%2C845&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/comzyh.com\/upload\/wordpress\/\/2010\/10\/SegmentTreeCount.png?fit=640%2C796&amp;ssl=1\" class=\"size-full wp-image-485\" title=\"SegmentTreeCount\" src=\"https:\/\/i0.wp.com\/comzyh.com\/upload\/wordpress\/\/2010\/10\/SegmentTreeCount.png?resize=640%2C796\" alt=\"\" width=\"640\" height=\"796\" data-recalc-dims=\"1\" \/><\/a><figcaption id=\"caption-attachment-485\" class=\"wp-caption-text\">\u5b8c\u5168\u4e8c\u53c9\u6811\u65b9\u5f0f\u5b58\u50a8\u7ebf\u6bb5\u6811\u7684\u7a7a\u95f4\u5360\u7528<\/figcaption><\/figure>\n<p>\u53ef\u4ee5\u770b\u5230,\u7a7a\u95f4\u590d\u6742\u5ea6\u5176\u5b9e\u662f\u6700\u597d\\(\\Theta(2N) \\),\u6700\u5dee\u662f\\(\\Theta(4N) \\),\u6700\u597d\u60c5\u51b5\u51fa\u73b0\u5728\u7565\u5c0f\u4e8e\\(2^{k}\\)\u9644\u8fd1,\u6700\u574f\u60c5\u51b5\u51fa\u73b0\u5728\u7565\u5927\u4e8e\\(2^{k}\\)\u9644\u8fd1,\u7531\u6b64\u770b\u6765,\u6211\u4eec\u4ee5\u540e\u5b58\u7ebf\u6bb5\u6811\u5927\u6982\u9700\u8981\u5f004N+100 \u7684\u6570\u7ec4\u5c31\u53ef\u4ee5\u4e86.<\/p>\n<p>\u9644\u7ebf\u6bb5\u6811\u7a7a\u95f4\u8ba1\u7b97\u7a0b\u5e8f:<\/p>\n<p>\u8f93\u5165\u533a\u95f4\u957f\u5ea6,\u4ed6\u6765\u544a\u8bc9\u4f60\u8981\u5f00\u591a\u5927\u6570\u7ec4.<\/p>\n<pre lang=\"Cpp\" file=\"CountSegment.cpp\">\r\n\/*\u7ebf\u6bb5\u6811\u7a7a\u95f4\u8ba1\u7b97\u7a0b\u5e8f Power By:Comzyh*\/\r\n#include <iostream>\r\n#include <cstdio>\r\n#include <cstdlib>\r\nusing namespace std;\r\nstruct segment {\r\n       int b,e;\r\n       };\r\nsegment seg[5000000];\r\nint N;\r\nint Nnode,LastNode;\r\nvoid build(int b, int e, int s);\r\nint main(){\r\n    while (1){\r\n          printf(\"Please Enter Interval length \u8bf7\u8f93\u5165\u533a\u95f4\u957f\u5ea6:\\n\");\r\n          scanf(\"%d\",&N);\r\n          if (N==0)return 0;\r\n          Nnode=0;\r\n          LastNode=0;\r\n          build(1,N,1);\r\n          printf(\"Complete binary tree, has build %d Nodes ,the last node numbered %d\\n %d \u6700\u540e\u4e00\u4e2a\u8282\u70b9:%d\\n\",Nnode,LastNode,Nnode,LastNode);\r\n          \/\/system(\"pause\");\r\n          }\r\n    }\r\nvoid build(int b, int e, int s){\r\n     Nnode++;\r\n     if (s>LastNode)\r\n        LastNode=s;\r\n     seg[s].b=b;\r\n     seg[s].e=e;\r\n     if (b==e)\r\n         return;\r\n     int mid =(b+e)>>1;\r\n     build(b,mid,s<<1);\r\n     build(mid+1,e,(s<<1)+1);\r\n     }\r\n\r\n<\/pre>\n<p>\u9644\u7ebf\u6bb5\u6811\u7a7a\u95f4\u5360\u7528\u5206\u6790\u7a0b\u5e8f(\u6253\u8868),\u4e0a\u9762\u90a3\u4e2a\u56fe\u7684\u8868\u5c31\u662f\u5b83\u8ba1\u7b97\u51fa\u6765\u7684:<\/p>\n<pre lang=\"Cpp\" file=\"CountSegmentFile.cpp\">\r\n\/*\u7ebf\u6bb5\u6811\u7a7a\u95f4\u5206\u6790\u7a0b\u5e8f Power By:Comzyh*\/\r\n#include <iostream>\r\n#include <cstdio>\r\n#include <cstdlib>\r\nusing namespace std;\r\nstruct segment {\r\n       int b,e;\r\n       };\r\nsegment seg[5000000];\r\nint N;\r\nint Nnode,LastNode;\r\nvoid build(int b, int e, int s);\r\nint main(){\r\n    freopen (\"segmentCount.csv\",\"w\",stdout);\r\n    int i=1;\r\n    scanf(\"%d\",&N);\r\n    printf(\"\u533a\u95f4\u957f\u5ea6,\u8282\u70b9\u6570,\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7f16\u53f7\\n\");\r\n    while (N-i>=0){\r\n          Nnode=0;\r\n          LastNode=0;\r\n          build(1,i,1);\r\n          printf(\"%d,%d,%d\\n\",i,Nnode,LastNode);\r\n          \r\n          i++;\r\n          }\r\n    \/\/system(\"pause\");\r\n    }\r\nvoid build(int b, int e, int s){\r\n     Nnode++;\r\n     if (s>LastNode)\r\n        LastNode=s;\r\n     seg[s].b=b;\r\n     seg[s].e=e;\r\n     if (b==e)\r\n         return;\r\n     int mid =(b+e)>>1;\r\n     build(b,mid,s<<1);\r\n     build(mid+1,e,(s<<1)+1);\r\n     }\r\n\r\n<\/pre>\n<p>\u7136\u540e\u6253\u4e86\u4e2a\u8868,\u53ef\u4ee5\u7528\u6765\u67e5\u8be2\u7ebf\u6bb5\u6811\u7a7a\u95f4<\/p>\n<pre lang=\"text\" colla=\"-\" file=\"SegmentCount.txt\">\r\n\u533a\u95f4\u957f\u5ea6  ,\u5360\u7528\u7a7a\u95f4 \r\n         1:1\r\n         2:3\r\n         3:5\r\n         4:7\r\n         5:9\r\n         6:13\r\n         7:13\r\n         8:15\r\n         9:17\r\n        10:25\r\n        10:25\r\n        20:57\r\n        30:61\r\n        40:121\r\n        50:125\r\n        60:125\r\n        70:225\r\n        80:249\r\n        90:249\r\n       100:253\r\n       200:509\r\n       300:1009\r\n       400:1021\r\n       500:1021\r\n       600:2033\r\n       700:2041\r\n       800:2045\r\n       900:2045\r\n      1000:2045\r\n      2000:4093\r\n      3000:8185\r\n      4000:8189\r\n      5000:16369\r\n      6000:16377\r\n      7000:16381\r\n      8000:16381\r\n      9000:32737\r\n     10000:32753\r\n     20000:65521\r\n     30000:65533\r\n     40000:131057\r\n     50000:131069\r\n     60000:131069\r\n     70000:262113\r\n     80000:262129\r\n     90000:262137\r\n    100000:262141\r\n    200000:524285\r\n    300000:1048561\r\n    400000:1048573\r\n    500000:1048573\r\n    600000:2097137\r\n    700000:2097145\r\n    800000:2097149\r\n    900000:2097149\r\n   1000000:2097149\r\n   2000000:4194301\r\n   3000000:8388601\r\n   4000000:8388605\r\n   5000000:16777201\r\n   6000000:16777209\r\n   7000000:16777213\r\n   8000000:16777213\r\n   9000000:33554401\r\n  10000000:33554417\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u5927\u5bb6\u5b58\u50a8\u7ebf\u6bb5\u6811\u7684\u65b9\u5f0f\u65e0\u975e\u4e24\u79cd\uff1a \u4e8c\u53c9\u94fe\u8868 \u4e00\u7ef4\u6570\u7ec4\u5b8c\u5168\u4e8c\u53c9\u6811 \u4e8c\u53c9\u94fe\u8868\u4f18\u70b9\u662f\u8282\u7701\u7a7a\u95f4,\u7f3a\u70b9\u662f\u7f16\u7a0b\u590d\u6742\u5ea6\u5927, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[11],"tags":[48,44],"class_list":["post-479","post","type-post","status-publish","format-standard","hentry","category-programing","tag-48","tag-44"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6XQWE-7J","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/posts\/479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/comments?post=479"}],"version-history":[{"count":3,"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/posts\/479\/revisions"}],"predecessor-version":[{"id":898,"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/posts\/479\/revisions\/898"}],"wp:attachment":[{"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/media?parent=479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/categories?post=479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/comzyh.com\/blog\/wp-json\/wp\/v2\/tags?post=479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}