{"id":719,"date":"2013-04-12T07:19:45","date_gmt":"2013-04-11T23:19:45","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=719"},"modified":"2013-04-13T04:01:41","modified_gmt":"2013-04-12T20:01:41","slug":"codeforces-round-179","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-179\/","title":{"rendered":"Codeforces Round #179"},"content":{"rendered":"<p><!--more--><\/p>\n<h2>Problem A. Greg and Array<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u3002\u3002\u7565\uff09<\/p>\n<h3>Analysis: <\/h3>\n<p>\u3002\u3002\u5176\u5b9e\u8fd9\u9898\u4e0d\u9700\u8981\u4f7f\u7528\u7ebf\u6bb5\u6811\u6216\u662f\u6811\u72b6\u6570\u7ec4\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002\u5bf9\u8fd9\u7c7b\u5404\u79cd\u64cd\u4f5c\u3002\u3002\u4e00\u6b21\u8be2\u95ee\u7684\u9898\u603b\u6709\u66f4\u76f4\u63a5\u7684\u5904\u7406\u65b9\u6cd5\u3002\u3002<\/p>\n<p>\u3002\u3002\u53c2\u89c1\u5496\u5561\u67a2\u7ebd\u3002\u3002\u3002<\/p>\n<p><a href=\"https:\/\/www.shuizilong.com\/house\/archives\/acm-icpc-world-finals-orlando-2011\/\">World Final 2011 Problem E. Coffee Central<\/a><br \/>\n<a href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-121\/\">Codeforces Round #121 Problem C. Fools and Roads<\/a><\/p>\n<h2>Problem C. Greg and Friends<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u3002\u3002n \u4e2a\u8d28\u91cf\u5206\u522b\u4e3a 1, 2 \u7684\u4eba\u9a7e\u9a76\u7740\u4e00\u8258\u8f7d\u91cd\u4e3a k \u7684\u5c0f\u8239\u6e21\u6cb3\u3002<br \/>\n\u3002\u3002\u95ee\u628a\u4eba\u5168\u90e8\u9001\u5230\u5bf9\u5cb8\u7684\u6700\u5c11\u5f80\u8fd4\u6b21\u6570\u3002\u3002\u3002\u4ee5\u53ca\u6ee1\u8db3\u6700\u5c11\u5f80\u8fd4\u6b21\u6570\u6761\u4ef6\u4e0b\u7684\u65b9\u6848\u6570\u3002\u3002<br \/>\n( n = 50\uff09\u3002\u3002<\/p>\n<h3>Analysis: <\/h3>\n<p>&#8230; \u4e2a\u4eba\u8ba4\u4e3a\u672c\u9898\u5341\u5206 Nice\u3002\u3002\u3002\u5f88\u5bb9\u6613\u60f3\u5230 dp[\u5f80\u8fd4\u6b21\u6570][1][2] \u7136\u540e\u679a\u4e3e [1][2] \u7684\u4eba\u6570\u8fd9\u79cd\u4e94\u6b21\u65b9 DP\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u6bd4\u8d5b\u65f6\u603b\u4f1a\u6709\u4eba\u8bef\u8ba4\u4e3a\u3002\u3002\u8fd4\u56de\u7684\u65f6\u5019\u4e00\u5b9a\u53ea\u642d\u4e581\u4e2a\u4eba\u624d\u80fd\u6700\u4f18\u3002\u3002\u3002\u3002<br \/>\n\u3002\u3002\u5b9e\u9645\u4e0a\u7ee7\u7eed\u89c2\u5bdf\u6211\u4eec\u4f1a\u53d1\u73b0\u3002\u3002\u5f80\u8fd4\u8fd9\u4e24\u4e2a\u8fc7\u7a0b\u3002\u3002\u5e76\u6ca1\u6709\u672c\u8d28\u4e0a\u7684\u5dee\u5f02\u3002\u3002\u3002\u5e94\u5199\u6210\u7edf\u4e00\u5f62\u5f0f\u3002\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = 59;\r\nInt f&#x5B;2]&#x5B;N]&#x5B;N], C&#x5B;N]&#x5B;N];\r\nint n, k, p, q, c1, c2;\r\n\r\nvoid Prep(){\r\n    swap(p, q); REP_2(a1, a2, c1+1, c2+1) f&#x5B;p]&#x5B;a1]&#x5B;a2] = 0;\r\n}\r\n\r\n#define b (b1+b2*2)\r\n\r\nvoid Roll(){\r\n    Prep(); REP_2(a1, a2, c1+1, c2+1) if (f&#x5B;q]&#x5B;a1]&#x5B;a2]) REP_2(b1, b2, a1+1, a2+1) if (b &amp;&amp;b &lt;= k){\r\n        f&#x5B;p]&#x5B;c1-a1+b1]&#x5B;c2-a2+b2] += C&#x5B;a1]&#x5B;b1] * C&#x5B;a2]&#x5B;b2] * f&#x5B;q]&#x5B;a1]&#x5B;a2];\r\n    }\r\n}\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    RD(n, k); k \/= 50; DO(n) if (RD()==50) ++c1; else ++c2;\r\n    REP(i, n+1){C&#x5B;i]&#x5B;0] = 1; REP_1(j, i) C&#x5B;i]&#x5B;j] = C&#x5B;i-1]&#x5B;j-1] + C&#x5B;i-1]&#x5B;j];}\r\n\r\n    p = 0, q = 1; Prep(); f&#x5B;p]&#x5B;c1]&#x5B;c2] = 1; REP(t, 2*n){\r\n\r\n        Roll();\r\n\r\n        if (f&#x5B;p]&#x5B;c1]&#x5B;c2]){\r\n            printf(&quot;%d\\n%d&quot;, t*2+1, int(f&#x5B;p]&#x5B;c1]&#x5B;c2]));\r\n            return 0;\r\n        }\r\n\r\n        Roll();\r\n    }\r\n\r\n    printf(&quot;-1\\n0&quot;);\r\n}\r\n<\/pre>\n<p>\u3002\u3002\u3002<br \/>\n<a href=\"http:\/\/codeforces.com\/contest\/295\/submission\/3515097\">http:\/\/codeforces.com\/contest\/295\/submission\/3515097<\/a><\/p>\n<h2>Problem D. Greg and Caves<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u7ed9\u5b9a\u4e00\u4e2a n*m \u7684\u683c\u70b9\u3002\u3002\u3002\u95ee\u53ef\u4ee5\u753b\u591a\u5c11\u79cd Caves\u3002\u3002\u3002<br \/>\n\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u56fe\u6848\u88ab\u79f0\u4e3a Caves \uff1a<br \/>\n\u3002\u3002\u56fe\u6848\u662f\u51f8\u7684\u3002\u3002\u4e0a\u4e0b\u7684\u5bbd\u5ea6\u81f3\u5c11\u662f 2.\u3002\u3002\u3002<br \/>\n\u3002\u3002\u4e14\u4e2d\u95f4\u5b58\u5728\u4e00\u4e2a\u6897\u3002\uff08\u53ef\u4ee5\u8986\u76d6\u5176\u4ed6\u6240\u6709\u884c\uff09\u3002\u3002<br \/>\n( n,m = 2000)<\/p>\n<h3>Analysis: <\/h3>\n<p>\u3002\u3002\u5927\u81f4\u4e5f\u53ef\u4ee5\u5f52\u7c7b\u5230<a href=\"https:\/\/www.shuizilong.com\/house\/archives\/glass_garden_problem\/\">\u57f9\u517b\u76bf\u95ee\u9898<\/a>\u3002\u3002\u4f46\u662f\u56e0\u4e3a\u4e2d\u95f4\u6709\u4e00\u4e2a\u6897\u800c\u4e14\u6ca1\u6709\u969c\u788d\u3002\u3002<\/p>\n<p>\u3002\u3002\u6240\u4ee5\u53ef\u4ee5 dp \u51fa\u4e00\u4e2a\u65b9\u5411\u7684\u7136\u540e\u8fde\u8d77\u6765\u3002\u3002\u3002<br \/>\n\u3002\u3002f[][] \u8868\u793a\u9ad8\u5ea6\u6070\u597d\u4e3a[]\u3002\u3002\u6897\u7684\u5bbd\u5ea6\u4e3a []\u3002\u3002<\/p>\n<p>\u8fd9\u4e2a dp \u51fa\u6765\u5927\u81f4\u662f\u8fd9\u6837\u3002\u3002<\/p>\n<pre>\r\n1 1 1 1 1 1 1 \r\n1 3 6 10 15 21 28 \r\n1 5 15 35 70 126 210 \r\n1 7 28 84 210 462 924\r\n<\/pre>\n<p>\u89c2\u5bdf\u53d1\u73b0\u5176\u5b9e\u8fd8\u662f\u7ec4\u5408\u6570\u3002\u3002\u3002<\/p>\n<pre>\r\nC(0, 0) C(1, 1) C(2, 2) C(3, 3)\r\nC(2, 0) C(3, 1) C(4, 2) C(5, 3)\r\nC(4, 0) C(5, 1) C(6, 2) C(7, 3)\r\nC(6, 0) C(7, 1) C(8, 2) C(9, 3)\r\n<\/pre>\n<p>\u3002\u3002\u3002\u5e94\u8be5\u53ef\u4ee5\u8054\u7cfb\u6321\u677f\u4ec0\u4e48\u7684\u7ed9\u51fa\u4e2a\u6bd4\u8f83\u5408\u7406\u7684\u7ec4\u5408\u89e3\u91ca\u3002\u3002\u3002\u53cd\u6b63\u6211\u662f\u600e\u4e48\u90fd\u4e0d\u884c\u3002\u3002<br \/>\n\u3002\u3002\u7136\u540e s[][] \u8868\u793a\u9ad8\u5ea6\u81f3\u591a\u4e3a []\u3002\u3002\u7136\u540e\u5bbd\u5ea6\u4e3a []\u3002\u3002\u3002\u3002<br \/>\n\u3002\u3002\u8fde\u8d77\u6765\u7684\u65f6\u5019\u7528 f[][] \u548c s[][] \u00d7\u8d77\u6765\u5c31\u597d\u3002<\/p>\n<p>\u3002s[][] \u53ef\u4ee5\u770b\u6210\u662f\u6d6e\u52a8\u7a97\u53e3\u3002\u3002\u4ece\u800c\u4e0d\u4f1a\u5f15\u8d77\u91cd\u590d\u8ba1\u6570\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = 2009;\r\nInt f&#x5B;N]&#x5B;N], s&#x5B;N]&#x5B;N];\r\nint n, m;\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    RD(n, m);\r\n\r\n    FOR_1(i, 2, m) f&#x5B;1]&#x5B;i] = 1; FOR_1(i, 2, n){Int s = 0; FOR_1(j, 2, m) f&#x5B;i]&#x5B;j] = (s += f&#x5B;i-1]&#x5B;j]) + f&#x5B;i]&#x5B;j-1];}\r\n    CPY(s, f); FOR_1(i, 2, n) FOR_1(j, 2, m) s&#x5B;i]&#x5B;j] += s&#x5B;i-1]&#x5B;j];\r\n    Int res = 0; REP_1(i, 1) FOR_1(j, 2, m) res += s&#x5B;i]&#x5B;j] * f&#x5B;n-i+1]&#x5B;j] * (m-j+1);\r\n\r\n    OT(res);\r\n}\r\n<\/pre>\n<h2>Problem E. Yaroslav and Points<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u3002\u3002x \u8f74 \u4e0a\u5206\u5e03\u7740 n \u4e2a\u70b9\u3002\u3002\u8981\u6c42\u652f\u6301\u4ee5\u4e0b\u4e24\u4e2a\u64cd\u4f5c\u3002\u3002<\/p>\n<ul>\n<li>\u8be2\u95ee\u6240\u6709\u8303\u56f4 [l, r] \u4e4b\u95f4\u7684\u70b9\u5bf9\u7684\u8ddd\u79bb\u7684\u548c\u3002<\/li>\n<li>\u79fb\u52a8\u5176\u4e2d\u4e00\u4e2a\u70b9\u7684\u5750\u6807\u3002<\/li>\n<\/ul>\n<h3>Analysis: <\/h3>\n<p>&#8230; \u4f3c\u4e4e\u65b9\u6cd5\u5f88\u591a\u3002\u3002\u4e0d\u8fc7\u679c\u7136\u8fd8\u662f Splay \u6700\u597d\u5f04\u4e86\u3002\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: update.cpp; toolbar: true; notranslate\" title=\"update.cpp\">\r\n\/*\r\n       x\r\n    &#x5B;l] &#x5B;r]\r\n*\/\r\n    inline void update(){\r\n        sz = l-&gt;sz + 1 + r-&gt;sz, s = l-&gt;s + ky + r-&gt;s; \/\/ size, sum ..\r\n        ss = l-&gt;ss + (l-&gt;sz*ky-l-&gt;s) + (l-&gt;sz*r-&gt;s - r-&gt;sz*l-&gt;s) + (r-&gt;s-r-&gt;sz*ky) + r-&gt;ss; \/\/ \u70b9\u5bf9\u548c\r\n               \/\/      x \u70b9\u548c\u5de6\u5b50\u6811\u3002\u3002\u3002     \/\/  \u8de8\u8d8a x \u70b9\u7684\u3002\u3002        \/\/ \u548c\u53f3\u5b50\u6811\u3002\u3002\r\n    }\r\n<\/pre>\n<p>\u3002\u3002\u5bf9\u4e8e\u8be2\u95ee\u64cd\u4f5c\u800c\u8a00\u3002\u3002\u3002\u662f\u53ef\u4ee5\u76f4\u63a5\u5728 splay \u91cc\u9762\u8fdb\u884c\u67e5\u627e\u7684\u3002\u3002\u4f46\u662f\u8981\u5199\u6210 lower_bound upper_bound \u90a3\u79cd\u7740\u5b9e\u6bd4\u8f83\u9ebb\u70e6\u3002\u3002<br \/>\n\u3002\u3002\u800c\u4fee\u6539\u64cd\u4f5c\u3002\u3002\u4e5f\u9700\u8981\u67e5\u627e\u67d0\u4e2a\u70b9\u7684\u4f4d\u7f6e\u3002\u3002\u800c\u4e14\u8003\u8651\u5230\u6ca1\u6709\u91cd\u590d\u7ed3\u70b9\u3002\u3002\u5199\u6210\u524d\u9a71\u540e\u7ee7\u7684\u8bdd\u66f4\u4e0d\u5bb9\u6613\u51fa\u9519\u3002\u3002<\/p>\n<p>\uff08\u3002\u3002xwlj \u7684 E \u9898\u5927\u88f8\u6570\u636e\u7ed3\u6784\u8981\u4e0d\u8981\u8fd9\u6837\u3002\u3002codeforces \u679c\u7136\u4e5f\u5f00\u59cb\u4e16\u98ce\u65e5\u4e0b\u4e86\u4e48\u3002\u3002<br \/>\n<a href=\"http:\/\/codeforces.com\/contest\/295\/submission\/3515011\">http:\/\/codeforces.com\/contest\/295\/submission\/3515011<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[18],"tags":[],"class_list":["post-719","post","type-post","status-publish","format-standard","hentry","category-codeforces"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-bB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/719","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=719"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/719\/revisions"}],"predecessor-version":[{"id":720,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/719\/revisions\/720"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}