{"id":1014,"date":"2014-10-08T12:06:21","date_gmt":"2014-10-08T04:06:21","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1014"},"modified":"2014-10-08T12:06:21","modified_gmt":"2014-10-08T04:06:21","slug":"spoj-707-triple-free-sets","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/spoj-707-triple-free-sets\/","title":{"rendered":"SPOJ 707. Triple-Free Sets"},"content":{"rendered":"<p><a href=\"http:\/\/www.spoj.com\/problems\/TFSETS\/\">http:\/\/www.spoj.com\/problems\/TFSETS\/<\/a><\/p>\n<h3>Brief description: <\/h3>\n<p>\u6c42\u6709\u591a\u5c11 {1..n} \u7684\u5b50\u96c6\uff0c\u6ee1\u8db3\u82e5 x \u5728\u8be5\u5b50\u96c6\u4e2d\uff0c\u5219 2x \u548c 3x \u4e0d\u5728\u8be5\u5b50\u96c6\u4e2d\u3002\uff08n \u2264 100000\uff09<\/p>\n<p><!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>\u540c <a href=\"http:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=2734\">HNOI 2012. \u96c6\u5408\u9009\u6570<\/a><\/p>\n<p>\u9700\u8981\u9884\u5904\u7406 + \u4e8c\u5206\u67e5\u627e\u3002\u3002\u3002\u3002\u3002<br \/>\n\u9996\u5148\u8003\u5bdf\u6240\u6709\u3002\u3002\u3002<br \/>\n2^a 3^b<\/p>\n<p>1<br \/>\n2 3<br \/>\n4 6 9<br \/>\n8 &#8230;<\/p>\n<p>\u90a3\u4e48 f(x) \u7684\u7ed3\u679c\u4e09\u89d2\u5f62\u586b\u6570\u3002\u3002\u8981\u6c42\u76f8\u90bb\u683c\u5b50\u4e0d\u80fd\u540c\u65f6\u4e3a 1.\u3002\u7684\u65b9\u6848\u6570\u3002\u3002\u3002\u3002<\/p>\n<p>\u5bf9\u4e8e\u6240\u6709\u975e 2^a 3^b \u7684\u6570 p\u3002\u3002\u3002\u5b83\u548c\u6240\u6709\u7684\u3002\u3002p 2^a 3^b \u53c8\u53ef\u4ee5\u5f62\u6210\u4e00\u7ec4\u4e09\u89d2\u5f62\u3002\u3002\u5f7c\u6b64\u72ec\u7acb\u3002\u3002\u4e58\u6cd5\u539f\u7406\u3002\u3002<\/p>\n<p>\u4e14\u6240\u6709\u7684\u4e09\u89d2\u5f62\u4e2d\u6700\u5927\u7684\u6570\u90fd\u662f 2^a 3^b \u7684\u5f62\u5f0f\u3002\u3002\u9884\u5904\u7406\u6240\u6709\u8fd9\u4e9b\u89e3\u3002\u3002\u65b9\u4fbf\u8d77\u89c1\u6211\u4eec\u65cb\u8f6c\u4e00\u4e0b<\/p>\n<p>1 3 9 27 &#8230;<br \/>\n  2 6 18 ..<\/p>\n<p>\u8fd9\u6837 m \u6700\u5927\u503c\u53ea\u6709 lg3(n)\u3002\u3002<\/p>\n<p><a href=\"http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2828033\">http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2828033<\/a><\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\nconst int N = (1e5) + 9, M = 12;\r\n\r\nvector&lt;PII&gt; I;\r\n\r\nint f(int n){\r\n\r\n    static bool Map&#x5B;N]&#x5B;M]; static Int F&#x5B;2]&#x5B;1&lt;&lt;M];\r\n\r\n    RST(Map); int r = 0, c = 0, x, xx;\r\n\r\n    for(r=0,x=1;x&lt;=n;++r,x*=2){\r\n        int j; for (j=0,xx=x;xx&lt;=n;++j,xx*=3) Map&#x5B;r]&#x5B;j] = 1;\r\n        if (!c) c = j;\r\n    }\r\n\r\n    int p = 0, q = 1; RST(F&#x5B;p]); F&#x5B;p]&#x5B;0]=1;\r\n\r\n    REP_2(i, j, r, c){\r\n        swap(p, q); RST(F&#x5B;p]);\r\n#define u F&#x5B;q]&#x5B;s]\r\n#define v0 F&#x5B;p]&#x5B;s&lt;&lt;1&amp;_U(c)]\r\n#define v1 F&#x5B;p]&#x5B;s&lt;&lt;1|1&amp;_U(c)]\r\n        REP(s, _1(c)) if (u){\r\n            v0 += u;\r\n            if (Map&#x5B;i]&#x5B;j] &amp;&amp; (!j || !_1(s, 0))) v1 += u;\r\n        }\r\n    }\r\n    Int z = 0; REP(s, _1(c)) z += F&#x5B;p]&#x5B;s];\r\n    return z;\r\n}\r\n\r\nint ff(int n){\r\n    Int z = 1; REP_1(i, n) if(i % 2 &amp;&amp; i % 3){\r\n        z *= (upper_bound(ALL(I), MP(n\/i, INF))-1)-&gt;se;\r\n    }\r\n    return z;\r\n}\r\n\r\nvoid Init(){\r\n    for (int x=1;x&lt;=N;x*=2){\r\n        for (int xx=x;xx&lt;=N;xx*=3) I.PB(MP(xx, f(xx)));\r\n    }\r\n    SRT(I);\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    Init(); Rush OT(ff(RD()));\r\n}\r\n\r\n\r\n<\/pre>\n<h3>References: <\/h3>\n<p><a href=\"http:\/\/ydcydcy1.blog.163.com\/blog\/static\/2160890402013195167512\/\">http:\/\/ydcydcy1.blog.163.com\/blog\/static\/2160890402013195167512\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/www.spoj.com\/problems\/TFSETS\/ Brief description: \u6c42\u6709\u591a\u5c11 {1..n} \u7684\u5b50\u96c6\uff0c\u6ee1\u8db3\u82e5 x \u5728\u8be5\u5b50\u96c6\u4e2d\uff0c\u5219 2x \u548c 3x \u4e0d\u5728\u8be5\u5b50\u96c6\u4e2d\u3002\uff08n \u2264 100000\uff09<\/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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[21],"tags":[],"class_list":["post-1014","post","type-post","status-publish","format-standard","hentry","category-spoj"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-gm","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1014","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=1014"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1014\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}