{"id":487,"date":"2024-05-17T09:00:00","date_gmt":"2024-05-17T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=487"},"modified":"2024-05-04T11:47:23","modified_gmt":"2024-05-04T03:47:23","slug":"zerojudge-b553","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-b553\/","title":{"rendered":"ZeroJudge B553: Collatz \u554f\u984c"},"content":{"rendered":"\n\n\n<p class=\"\">CollatzCollatz CollatzCollatz \u554f\u984c \uff08\u53c8\u7a31 \u300c3N +1\u300d\u554f\u984c \uff09\uff0c\u4e00\u958b\u59cb\u7d66\u5b9a\u500b\u5927\u65bc 1 \u7684\u6b63\u6574\u6578 N\uff0c\u5176\u8b8a\u63db\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"\">\u82e5 N \u70ba\u5076\u6578 (\u5373 N \u53ef\u88ab 2 \u6574\u9664\uff09\uff0c\u5247\u628a N \u9664\u4ee5 2\uff0c\u5373 N \u2192 N \u00f7 2\u3002<\/li>\n\n\n\n<li class=\"\">\u82e5 N \u70ba\u5927\u65bc 1 \u7684\u5947\u6578  (\u5373 N \u4e0d\u53ef\u88ab 2 \u6574\u9664\uff09\uff0c\u5247\u628a N \u4e58 3 \u518d\u52a0 1\uff0c\u5373 N \u2192 (3N +1\uff09\u3002<\/li>\n\n\n\n<li class=\"\">\u82e5 N \u70ba 1\uff0c\u5247\u7d50\u675f\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"\">\u6bd4\u5982\u8aaa\u5f9e 5 \u958b\u59cb\u7684\u8a71\uff0c \u5176\u8b8a\u63db\u7684\u6b65\u9a5f\u5982\u4e0b\uff1a 5 \u2192 5\u00d73+1=16 \u2192 16 \u00f72=8 \u2192 8\u00f72=4 \u2192 4\u00f72=2 \u2192 2\u00f72=1<\/p>\n\n\n\n<p class=\"\">\u518d\u8209\u500b\u4f8b\u5b50\uff0c\u6700\u958b\u59cb\u7684\u6578\u53d6 7\uff0c\u6211\u5011\u5f97\u5230\u4e0b\u9762\u7684\u5e8f\u5217\uff1a<br>7\u219222 \u219211 \u219234 \u219217 \u219252 \u219226 \u219213 \u219240 \u219220 \u219210 \u21925\u219216 \u21928\u21924\u21922\u21921<br>\u9019\u6b21\u8907\u96dc\u4e86\u4e00\u9ede\uff0c \u5176\u4e2d\u4e00\u5171\u505a\u4e86 16 \u6b21\u7684\u8b8a\u63db\uff0c \u4f46\u662f \u6211\u5011\u6700\u7d42\u9084\u505c\u6b62\u5728 1<\/p>\n\n\n\n<p class=\"\">\u73fe\u5728\u8981\u8acb\u4f60\u5beb\u4e00\u500b\u7a0b\u5f0f\u4f86<strong>\u6c42\u51fa\u8f49\u63db\u7684\u6b21\u6578<\/strong> \u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u6e2c\u8a66\u8cc7\u6599\u70ba\uff11\uff5e10 \u5217\u4ee5 <strong>EOF<\/strong> \u7d50\u675f\uff0c\u6bcf\u5217\u70ba\u4e00\u500b \u6b63\u6574\u6578 N\uff0c\u5176\u503c\u4ecb\u65bc 2 \u81f3 30000 \u3002<\/td><td>\u5c0d\u6bcf\u5217\u8f38\u5165\uff0c\u8f38\u51fa\u8cc7\u6599\u70ba\u4e00\u500b\u6b63\u6574\u6578\uff0c \u5171\u8981\u505a\u591a\u5c11\u6b21\u8b8a\u63db N \u624d\u6703\u505c\u6b62\u5728 1\u3002<\/td><\/tr><tr><td>3<br>5<br>7<\/td><td>7<br>5<br>16<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u5ba3\u544a\u4e00\u500b\u51fd\u5f0f\uff0c\u56de\u50b3\u503c\u6703\u9700\u8981\u5169\u500b\u6574\u6578\uff0c\u5206\u5225\u662f<strong>\u76ee\u524d\u904b\u7b97\u7684\u6578\u5b57\u4ee5\u53ca\u904b\u7b97\u6b21\u6578<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u6bcf\u4e00\u6b21\u5224\u65b7 3N+1 \u554f\u984c\u7684\u6642\u5019\u90fd\u8981\u56de\u50b3\u6578\u503c\uff0c\u7136\u5f8c\u8a18\u5f97\u6bcf\u6b21\u7684\u904b\u7b97\u6b21\u6578\u90fd\u8981 +1\uff0c\u5982\u679c\u904b\u7b97\u6578\u5b57\u70ba 1\uff0c\u5247 return \u904b\u7b97\u6b21\u6578\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=b553\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge B553: Collatz \u554f\u984c<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint calc(int N, int count)\n{\n    if (N == 1) return count;\n    if (N % 2 == 1) return calc((3*N)+1, count+1);\n    return calc(N\/2, count+1);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    while (cin &gt;&gt; N)\n    {\n        cout &lt;&lt; calc(N, 0) &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge B553\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>CollatzCollatz CollatzCollatz \u554f\u984c \uff08\u53c8\u7a31 \u300c3N +1\u300d\u554f\u984c \uff09\uff0c\u4e00\u958b\u59cb\u7d66\u5b9a\u500b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[29],"tags":[8,13],"class_list":["post-487","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-8","tag-13"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=487"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/487\/revisions"}],"predecessor-version":[{"id":488,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/487\/revisions\/488"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}