{"id":281,"date":"2012-07-04T02:03:50","date_gmt":"2012-07-03T18:03:50","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=281"},"modified":"2012-07-08T03:05:53","modified_gmt":"2012-07-07T19:05:53","slug":"srm-484","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/srm-484\/","title":{"rendered":"SRM 484"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>Problem 250. RabbitNumber (\u5154\u5b50\u6570 &#8230;<br \/>\n\u95ee [l, r] \u533a\u95f4\u5185 &#8220;\u5154\u5b50\u6570&#8221; \u7684\u6570\u5b57\u6709\u591a\u5c11\u3002<br \/>\n\u5154\u5b50\u6570\u4e3a\u6ee1\u8db3 S(x^2) = S(x)^2 \u7684\u6570\u5b57, \u8fd9\u91cc S(x) \u4e3a x \u7684\u6570\u4f4d\u548c\u3002<br \/>\n( .. . 1 <= l, r <= 10^9 .. )\n\nProblem 550. PuyoPuyo \n\u4e00\u4e2a\u5806\u6808, \u53ef\u4ee5\u5f80\u91cc\u9762\u653e 4 \u79cd\u989c\u8272\u7684\u7403\uff0c\u5f53\u6808\u9876\u8fde\u7eed L \u4e2a\u7403\u989c\u8272\u76f8\u540c\u65f6\uff0c\u6d88\u53bb\u8fd9 L \u4e2a\u7403\u3002\n\u95ee\u5f80\u91cc\u9762\u653e n \u4e2a\u7403\u7684\u8bdd\u6709\u591a\u5c11\u79cd\u653e\u6cd5\u4f7f\u5f97\u6808\u7a7a\u3002\n( . ..n <= 1000, L <=10 .. .)\n\nProblem 950. NumberMagic (\u731c\u6570\u6e38\u620f\u3002\u3002\nTaro \u5728\u5fc3\u4e2d\u60f3\u4e86\u4e00\u4e2a 1\uff5en \u4e4b\u95f4\u7684\u6570\u5b57 x\uff0cHanako \u6bcf\u6b21\u53ef\u4ee5\u8be2\u95ee\u4e00\u4e2a m \u5927\u5c0f\u7684\u96c6\u5408\u3002\nTaro \u8fd4\u56de x \u5728 \/ \u4e0d\u5728 \u5176\u4e2d\u3002\u3002\u3002\u95ee\u81f3\u5c11\u591a\u5c11\u6b21\u8be2\u95ee\u4e00\u5b9a\u53ef\u4ee5\u731c\u51fa\u8fd9\u4e2a\u6570\u3002\n\n<!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>Problem 250. RabbitNumber<br \/>\n\u3002\u8c8c\u4f3c\u66b4\u529b DFS() \u53ef\u8fc7\u3002\u3002<br \/>\n( \u53ef\u4ee5\u63a8\u51fa\u5154\u5b50\u6570\u5c31\u662f\u6ee1\u8db3 x^2 \u4e0d\u4ea7\u751f\u8fdb\u4f4d\u7684\u6570\u3002\u3002(\u3002\u3002\u53cd\u8bc1\u7acb\u5f97\u3002\u3002\u4e00\u65e6\u4ea7\u751f\u8fdb\u4f4d\u5219\u5fc5\u7136\u6709\u6240\u635f\u8017\u3002\u3002\u3002<br \/>\n( \u5219\u6bcf\u4e00\u4f4d\u53ea\u80fd\u662f [0, 3] \u3002\u3002\u5e76\u4e14\u524d\u7f00\u4e00\u5b9a\u4e5f\u662f\u5154\u5b50\u6570\u3002\u3002\u3002<\/p>\n<p>Problem 550. PuyoPuyo<br \/>\n\u7565\u3002( dp[i][j] \u4e3a\u5f53\u524d\u4f7f\u7528\u4e86 i \u4e2a\u7403, \u8fd8\u9700\u8981 j \u4e2a\u7403\u624d\u80fd\u5f7b\u5e95\u6d88\u5b8c\u7684\u65b9\u6848\u6570\u3002\u3002\u3002<\/p>\n<p>Problem 950. NumberMagic (\u731c\u6570\u6e38\u620f\u3002\u3002<br \/>\n\u8981\u4e00\u5b9a\u80fd\u731c\u51fa\u8fd9\u4e2a\u6570\uff0c\u5219\u5728\u6240\u6709\u8be2\u95ee\u4e2d\uff0c\u67d0\u4e24\u4e2a\u6570\u4e0d\u80fd\u603b\u662f\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u51fa\u73b0\uff08\u5426\u5219\u65e0\u6cd5\u533a\u5206\u5f00\u3002\u3002<br \/>\n\u3002\u3002\u4e5f\u5c31\u662f\u5bf9\u4efb\u610f\u7684 i, j\uff0c\u90fd\u6709 {Si} \u4e0d\u540c\u4e8e {Sj} \u3002\u3002\u3002\uff08 {Si} \u8868\u793a\u5305\u542b i \u7684\u8be2\u95ee\u96c6\u5408\u3002\u3002<\/p>\n<p>\u8bbe f(n, m) \u8868\u793a\u6240\u6c42\u51fd\u6570\u3002\u3002<br \/>\n&#8230; \u7136\u540e\u8fd9\u4e2a\u9898\u5f88\u5bb9\u6613\u8ba9\u4eba\u5f80\u4e0d\u5bf9\u7684\u5730\u65b9\u60f3 \u3002\u3002\u3002<br \/>\n\u786e\u5b9e\u4e5f\u53ef\u4ee5\u5f97\u5230\u4e00\u4e9b\u6027\u8d28\u3002\u3002\u4f8b\u5982<br \/>\nf(n, m) = f(n, n &#8211; m)\u3002\uff08\u56e0\u800c\u8be5\u51fd\u6570\u7c7b\u4f3c\u7ec4\u5408\u6570\u3002\u662f\u5bf9\u79f0\u7684\u3001\u5355\u5cf0\u7684\u3001\u4e0d\u8fc7\u662f\u51f9\u7684\u3002\u3002<br \/>\nf(2^k, 2^(k-1)) = k \u3002<br \/>\n\u751a\u81f3\u8fd8\u6709\u5728 m \u7b49\u4e8e\u67d0\u4e9b\u56fa\u5b9a\u7684\u503c\u65f6\uff0c\u80fd\u5206\u6790\u51fa\u89e3\u3002\u3002\u3002<br \/>\n\u4f46\u662f\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u4e0d\u80fd\u5e94\u7528\u5230\u4e00\u822c\u60c5\u51b5\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: example-filename.cpp; toolbar: true; notranslate\" title=\"example-filename.cpp\">\r\nint f(LL x){\r\n\tint s = 0;\r\n\twhile (x) s += x%10, x\/=10;\r\n\treturn s;\r\n}\r\n\r\nclass RabbitNumber{\r\npublic:\r\n    int L, R, res;\r\n\tvoid dfs(LL x, LL s){\r\n\t\tif (s &gt; 14 || x &gt; 1e9) return;\r\n\t\tif (L&lt;=x &amp;&amp; x&lt;=R)\r\n\t\t\tif (s*s==f(x*x)) res++;\r\n\t\tfor (int i=0;i&lt;4;i++)\r\n\t\t\tdfs(x*10+i, s+i);\r\n\t}\r\n\r\n\tint theCount(int l, int r){\r\n\t\tL = l, R = r, res = 0; if (R==1e9) res++, R--;\r\n\t\tfor (int i=1;i&lt;4;i++) dfs(i, i);\r\n\t\treturn res;\r\n\t}\r\n};\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: example-filename.cpp; toolbar: true; notranslate\" title=\"example-filename.cpp\">\r\nconst int N = 1009, M = 10009;\r\n\r\nint dp&#x5B;N]&#x5B;N];\r\n\r\nclass PuyoPuyo {\r\npublic:\r\n\tint theCount(int l, int n) {\r\n\r\n\t\tRST(dp), dp&#x5B;0]&#x5B;0] = 1; REP(i, n) {\r\n\t\t    INC(dp&#x5B;i+1]&#x5B;l-1], pdt(4, dp&#x5B;i]&#x5B;0]));\r\n            REP_1(j, min(n-i, (l-1) * i)){\r\n                INC(dp&#x5B;i+1]&#x5B;j-1], dp&#x5B;i]&#x5B;j]);\r\n                INC(dp&#x5B;i+1]&#x5B;j+(l-1)], pdt(3, dp&#x5B;i]&#x5B;j]));\r\n            }\r\n\t\t}\r\n\r\n\t\treturn dp&#x5B;n]&#x5B;0];\r\n\t}\r\n};\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: Problem 1000. NumberMagic.cpp; toolbar: true; notranslate\" title=\"Problem 1000. NumberMagic.cpp\">\r\n.. .\r\nint n, m;\r\n\r\nLL C(int n, int m){\r\n    LL res = 1; REP_1(i, m) res *= (n - i + 1), res \/= i;\r\n    return res;\r\n}\r\n\r\nbool check(int k){\r\n    LL r = (LL) m * k; int n = ::n, t;\r\n    for (int i=0;i&lt;=k&amp;&amp;n&amp;&amp;r&gt;=0;++i){\r\n        t = min(C(k, i), (LL) n);\r\n        n -= t, r -= (LL) i * t;\r\n    }\r\n    return r &gt;= 0 &amp;&amp; n == 0;\r\n}\r\n\r\nclass NumberMagic {\r\npublic:\r\n\tint theMin(int n, int m) {\r\n\t    m = min(m, n - m), ::n = n, ::m = m;\r\n        int l = 0, r = n - 1;\r\n        while (l &lt; r){\r\n            int k = (l + r) &gt;&gt; 1;\r\n            if (check(k)) r = k;\r\n            else l = k + 1;\r\n        }\r\n        return l;\r\n\t}\r\n};\r\n<\/pre>\n<p>\u561b\u3002\u3002\u603b\u4e4b\u8fd8\u662f\u770b\u9898\u89e3\u548c\u7a0b\u5e8f\u91cd\u65b0\u7406\u601d\u8def\u4e86\u5427\u3002\u3002<br \/>\n\u6700\u5173\u952e\u7684\u5730\u65b9\u5728\u4e8e\u5148 Ban \u6389 m \u8fd9\u4e2a restriction\u3002\u3002\u3002<br \/>\n\u8981\u70b9\u662f\u6ce8\u610f\u5230\u4ee5\u4e0b\u5f15\u7406\uff1a<\/p>\n<blockquote><p>If it is possible to place a total of M*K numbers on K cards in a way that satisfies the original condition, it is possible to place exactly M numbers on each of K cards in a way that satisfies the original condition.<\/p><\/blockquote>\n<p>\u5982\u679c\u53ef\u4ee5\u603b\u5171\u5728 k \u6b21\u8be2\u95ee\u4e2d\uff0c\u5171\u5305\u542b m*k \u4e2a\u6570\uff0c\u5219\u53ef\u4ee5\u5728\u8fd9 k \u6b21\u8be2\u95ee\u4e2d\uff0c\u6bcf\u6b21\u8be2\u95ee\u6070\u597d m \u4e2a\u6570\u3002\u3002\uff08\u3002\u3002\u3002<\/p>\n<p>\u4e4b\u540e\u5c31\u662f\u8003\u8651\u9a8c\u8bc1\u7b54\u6848\u7684\u51fd\u6570 bool check(k); \u4e86\u3002\u3002<br \/>\n\u3002\u4e0b\u9762\u7ed9\u51fa\u6784\u9020\u65b9\u6848\u3002\u3002\uff08 k \u592a\u5c0f\u7684\u8bdd\u6784\u9020\u4e0d\u51fa\u6ee1\u8db3\u6761\u4ef6\u7684\u89e3\u3002\u3002<\/p>\n<p>\u4f9d\u6b21\u679a\u4e3e\u6709\u591a\u5c11\u4e2a\u6570\u5b57\uff0c\u5728\u8be2\u95ee\u4e2d\u51fa\u73b0\u4e86\u6070\u597d i \u6b21<br \/>\n\u3002\u3002\u8003\u8651\u5230 \u201c\u7528\u6599\u6700\u7701\u201d \u7684\u539f\u5219\u3002\u3002\uff08\u540c\u65f6\u53c8\u8981\u6ee1\u8db3\u6700\u5f00\u59cb\u6240\u8ff0\u7684\u6761\u4ef6\u3002\u3002\u3002<br \/>\n\u3002\u30020 \u6b21 \u7684\u53ea\u80fd\u6709 1 \u4e2a\u6570\u5b57\u3002\u3002\uff08\u5982\u679c\u6709 2 \u4e2a\u5219\u65e0\u6cd5\u533a\u5206\u5f00\u3002\u3002<br \/>\n\u3002\u30021 \u6b21 \u7684\u53ea\u80fd\u6709 k \u4e2a\u6570\u5b57\u3002\u3002\uff08\u6bcf\u5f20\u724c\u5360\u4e00\u4e2a\u3002\u3002<br \/>\n\u3002\u30022 \u6b21 \u7684\u53ea\u80fd\u6709 C(k, 2) \u4e2a\u6570\u5b57\u3002\u3002\u3002\u3002\uff08\u3002\u3002\u540c\u7406\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u3002<br \/>\n\u3002\u3002K \u6b21 \u7684\u53ea\u80fd\u6709 C(k, k) \u4e2a\u6570\u5b57\u3002\u3002\u3002<\/p>\n<p>\u5f53\u7136\u6ce8\u610f\u5230\u5bf9\u540e\u9762\u4e00\u7ec4\u7684\u7ec4\u5408\u9879\u7684\u6c42\u548c\u4e2d\u95f4\u4f1a\u8d85\u8fc7 N \u7684\u95ee\u9898\u3002\u3002\u3002<br \/>\n\u540c\u65f6\u5b58\u5728\u4e00\u79cd\u5bf9\u79f0\u7684\u6784\u9020\u3002\u3002\u3002\u65e2\u3002\u3002<\/p>\n<p>\u3002\u3002K \u6b21 \u7684\u53ea\u80fd\u6709 1 \u4e2a\u6570\u5b57\u3002\u3002\uff08\u5982\u679c\u6709 2 \u4e2a\u5219\u65e0\u6cd5\u533a\u5206\u5f00\u3002\u3002<br \/>\n\u3002\u3002K-1 \u6b21 \u7684\u53ea\u80fd\u6709 k \u4e2a\u6570\u5b57\u3002\u3002\uff08\u6bcf\u5f20\u724c\u5360\u4e00\u4e2a\u3002\u3002<br \/>\n\u3002\u3002K-2 \u6b21 \u7684\u53ea\u80fd\u6709 C(k, 2) \u4e2a\u6570\u5b57\u3002\u3002\u3002\u3002\uff08\u3002\u3002\u540c\u7406\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u3002<br \/>\n\u3002\u30020 \u6b21 \u7684\u53ea\u80fd\u6709 C(k, k) \u4e2a\u6570\u5b57\u3002\u3002\u3002<\/p>\n<p>\u6ce8\u610f\u5230\u5982\u679c\u4e2d\u95f4\u6ca1\u6709\u53d1\u751f\u8d85\u8fc7 N \u7684\u4e8b\u4ef6\u3002\u3002\u4e5f\u5c31\u662f N = 2^k \u6b21\u65b9\u7684\u8bdd\u3002\u3002<br \/>\n\u8fd9\u4e24\u79cd\u6784\u9020\u51fa\u6765\u7684 1 \u7684\u4e2a\u6570\u662f\u4e00\u6837\u591a\u7684\u3002\u3002\u3002<\/p>\n<p>\u8fd9\u4e24\u79cd\u6784\u9020\u662f\u5bf9\u79f0\u7684\u3002\u3002\u77e5\u9053\u5176\u4e2d\u4e00\u4e2a\u7684\u7ed3\u679c\u3002\u3002\u53e6\u4e00\u4e2a\u53ef\u4ee5\u7528 nk \u76f8\u51cf\u5f97\u5230\u3002\u3002<br \/>\n\uff08\u3002\u5316\u7b80\u540e\u3002\u3002\u903b\u8f91\u4e0a\u7406\u89e3\u5373\u53d6\u53cd\u3002\u3002\u3002<\/p>\n<p>\u4e8e\u662f\u5bf9\u4efb\u610f\u7684 k \u5c06\u4f1a\u5f97\u5230\u4e00\u4e2a minT \u548c maxT\u3002\u3002\u3002<br \/>\n\u4ee5\u4e0b\u53c8\u4ea7\u751f\u4e86\u4e00\u4e9b\u95ee\u9898\u3002\u3002<\/p>\n<p>\u662f\u5426\u6240\u4ee5 minT ~ maxT \u4e4b\u95f4\u7684\u6570\u90fd\u53ef\u4ee5\u6784\u9020\u51fa\u3002\u3002<br \/>\n\u3002\u8fd9\u4e2a\u533a\u95f4\u662f\u5426\u53ef\u4ee5\u5305\u542b mk\u3002\u3002\u3002<\/p>\n<p>\uff08\u3002\u3002\u8bc1\u660e\u4e0d\u80fd\u3002\u3002<br \/>\n\u524d\u9762\u6240\u8bf4\u7684 f(2^k, 2^(k-1)) = k \u3002\u3002\u8fd9\u79cd\u3002\u3002<br \/>\n\u5c31\u662f minT = maxT \u7684\u60c5\u51b5 \u3002\u3002\uff08\u3002\u3002\u800c\u4e14\u8fd9\u4e2a\u503c\u6070\u597d\u662f mk \u3002\u3002\u3002<\/p>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/www.hhanger.com\/?p=675\">http:\/\/www.hhanger.com\/?p=675<\/a><br \/>\n<a href=\"http:\/\/apps.topcoder.com\/wiki\/display\/tc\/SRM+484\">http:\/\/apps.topcoder.com\/wiki\/display\/tc\/SRM+484<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: Problem 250. RabbitNumber (\u5154\u5b50\u6570 &#8230; \u95ee [l, r] \u533a\u95f4\u5185 &#8220;\u5154\u5b50\u6570&#8221; \u7684\u6570\u5b57\u6709\u591a\u5c11\u3002 \u5154\u5b50\u6570\u4e3a\u6ee1\u8db3 S(x^2) = S(x)^2 \u7684\u6570\u5b57, \u8fd9\u91cc S(x) \u4e3a x \u7684\u6570\u4f4d\u548c\u3002 ( .. . 1<\/p>\n","protected":false},"author":1,"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":[17],"tags":[80],"class_list":["post-281","post","type-post","status-publish","format-standard","hentry","category-topcoder","tag-80"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-4x","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=281"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/281\/revisions"}],"predecessor-version":[{"id":282,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/281\/revisions\/282"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}