{"id":567,"date":"2020-05-25T10:41:25","date_gmt":"2020-05-25T02:41:25","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=567"},"modified":"2020-07-05T18:01:30","modified_gmt":"2020-07-05T10:01:30","slug":"bitset%e4%bb%8b%e7%bb%8d%e4%b8%8e%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/05\/25\/bitset%e4%bb%8b%e7%bb%8d%e4%b8%8e%e4%bd%bf%e7%94%a8\/","title":{"rendered":"bitset\u4ecb\u7ecd\u4e0e\u4f7f\u7528"},"content":{"rendered":"<h3>bitset<\/h3>\n<p>bitset\u6570\u636e\u7c7b\u578b\uff0c\u5728\\&lt;bitset>\u5934\u6587\u4ef6\u4e2d\uff0c\u662f\u4e00\u79cd\u7c7b\u4f3c\u4e8e\u6570\u7ec4\u548c\u5b57\u7b26\u4e32\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p>bitset\u7684\u6bcf\u4e00\u4e2a\u5355\u4f4d\u6240\u5360\u5185\u5b58\u5927\u5c0f\u4e3a1\u4e2a\u4f4d\uff0c\u662fint\u7c7b\u578b\u7684<code class=\"katex-inline\">\\frac{1}{32}<\/code>\uff0c\u540c\u65f6\u8fd8\u652f\u6301\u4e00\u4e9b\u4f4d\u8fd0\u7b97\uff0c\u6bd4bool\u8fd8\u597d\u7528\u3002<\/p>\n<p>\u53ef\u4ee5\u628abitset\u5f53\u6210\u4e00\u4e2a\u957f\u5ea6\u53ef\u81ea\u5b9a\u4e49\u7684\u4e8c\u8fdb\u5236\u6570\uff0c\u8fd9\u6837\u4f4d\u8fd0\u7b97\u5c31\u80fd\u60f3\u901a\u4e86\u3002<\/p>\n<h4>\u6784\u9020\u51fd\u6570<\/h4>\n<p>bitset\u662f\u4e00\u4e2a\u7c7b\u4f3c\u6570\u7ec4\u7684\u53d8\u91cf\uff0c\u6240\u4ee5\u5b9a\u4e49\u662f\u5fc5\u987b\u662fbitset\\&lt;size>\u7684\u5f62\u5f0f\uff0c\u5373\u8981\u58f0\u660e\u6570\u7ec4\u5927\u5c0f\uff0c\u652f\u6301\u4e0b\u6807\u8bbf\u95ee\uff01\uff08\u4e0b\u6807\u540c\u6570\u7ec4\uff0c\u4ece0\u5230size-1\uff09<\/p>\n<p>\u5b9a\u4e49\u4e00\u4e2abitset\u7c7b\u578b\u53d8\u91cf\u7684\u65b9\u6cd5\u6709\u4ee5\u4e0b\u51e0\u79cd<\/p>\n<pre><code class=\"language-c++\">\/\/\u4e0d\u53ef\u4ee5\u4e0d\u58f0\u660esize\nbitset a;   \/\/\u62a5\u9519\n\n\/\/\u65e0\u53c2\uff0c\u9ed8\u8ba4\u503c0\nbitset&lt;size&gt; a;\n\n\/\/\u6574\u578b\u6570b\u4e3a\u53c2\u6570\uff0c\u90a3\u4e48a\u7684\u503c\u5c31\u662fb\u7684\u4e8c\u8fdb\u5236\u8868\u793a\uff0c\u9760\u53f3\u5bf9\u9f50\uff0c\u5de6\u8fb9\u88650\nbitset&lt;size&gt; a(int b);\n\n\/\/\u5b57\u7b26\u4e32string\u7c7b\u578bb\u4e3a\u53c2\u6570\uff0cb\u4e2d\u53ea\u80fd\u6709&#039;0&#039;\u548c&#039;1&#039;\uff0c\u5426\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u9760\u53f3\u5bf9\u9f50\uff0c\u5de6\u8fb9\u88650\nbitset&lt;size&gt; a(string b);\n\n\/\/\u5b57\u7b26\u4e32\u6570\u7ec4\u4e3a\u53c2\u6570\uff0c\u540cstring\nbitset&lt;size&gt; a(char[] b);\n\n\/\/\u7c7b\u4f3c\u4e8e\u5b57\u7b26\u4e32\u662f\u56e0\u4e3a\u53ef\u4ee5\u628abitset\u5f53\u6210\u5b57\u7b26\u4e32\u76f4\u63a5\u8f93\u51fa      \u6ce8\u610fbitset\u7684\u8f93\u51fa\u662f\u6309a[n-1]-a[0]\u987a\u5e8f\u8f93\u51fa\u7684\uff0c\u4e0estring\u548c\u5b57\u7b26\u6570\u7ec4\u76f8\u53cd\ncout &lt;&lt; a &lt;&lt; endl;<\/code><\/pre>\n<h4>\u64cd\u4f5c\u7b26<\/h4>\n<p>\u652f\u6301 ~\u3001&amp;\u3001|\u3001^\u3001&lt;&lt;\u3001&gt;&gt;\u3001&amp;=\u3001|=\u3001^=\u3001&lt;&lt;=\u3001&gt;&gt;=\u8fd8\u6709==\u3001!=\u7b49\u64cd\u4f5c\u7b26\u3002\u4f4d\u8fd0\u7b97\u5c31\u662f\u628abitset\u5f53\u6210\u4e8c\u8fdb\u5236\u6570\u8fdb\u884c\u6309\u4f4d\u8fd0\u7b97\u3002<\/p>\n<p>\u5404\u64cd\u4f5c\u7b26\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u6682\u5b9a\u3002\u3002\u3002<\/p>\n<p>\u5c31\u4e0d\u4e3e\u4f8b\u5b50\u4e86\u3002<\/p>\n<h4>\u51fd\u6570<\/h4>\n<p>bitset\u652f\u6301\u4e00\u4e9b\u6709\u7528\u7684\u51fd\u6570<\/p>\n<pre><code class=\"language-c++\">    bitset&lt;size&gt; a;\n\n    \/\/count()\u51fd\u6570\u7528\u6765\u6c42bitset\u4e2d1\u7684\u4f4d\u6570\n    cout &lt;&lt; a.count() &lt;&lt; endl;\n\n    \/\/size()\u51fd\u6570\u6c42bitset\u7684\u5927\u5c0f\n    cout &lt;&lt; a.size() &lt;&lt; endl;\n\n    \/\/test(i)\u51fd\u6570\u5bf9\u4e0b\u6807i\u8fdb\u884c\u68c0\u67e5\uff0c\u4e0b\u6807\u662f\u5426\u5408\u6cd5\uff08\u8d8a\u754c\u629b\u51fa\u5f02\u5e38\uff09\uff0c\u4ee5\u53ca\u8be5\u4e0b\u6807\u51fa\u7684\u503c\u4e3a0\u8fd8\u662f1\n    cout &lt;&lt; a.test(0) &lt;&lt; endl;\n\n    \/\/any()\u51fd\u6570\u68c0\u67e5\u662f\u5426\u67091\n    cout &lt;&lt; a.any() &lt;&lt; endl;\n\n    \/\/none()\u51fd\u6570\u68c0\u67e5\u662f\u5426\u6ca1\u67091\n    cout &lt;&lt; a.none() &lt;&lt; endl;\n\n    \/\/all()\u51fd\u6570\u68c0\u67e5\u662f\u5426\u5168\u4e3a1\n    cout &lt;&lt; a.all() &lt;&lt; endl;\n<\/code><\/pre>\n<h4>\u7c7b\u578b\u8f6c\u5316<\/h4>\n<p>bitset\u53ea\u652f\u6301\u4e09\u79cd\u7c7b\u578b\u8f6c\u5316: string, unsigned long, unsigned long long. \u6ce8\u610fbitset\u5b58\u7684\u662f\u4e8c\u8fdb\u5236\u6570\uff0c\u8f6c\u5316\u4e3a\u6574\u6570\u65f6\u4f1a\u81ea\u52a8\u8fdb\u884c\u8f6c\u5316\u3002<\/p>\n<pre><code class=\"language-c++\">bitset&lt;size&gt; a;\n\nstring s = a.to_string();\n\nunsigned long b = a.to_ulong();\n\nunsigned long long c = a.to_ullong();<\/code><\/pre>\n<h5><a href=\"https:\/\/ac.nowcoder.com\/acm\/problem\/17193\">NC17193 \u7b80\u5355\u778e\u641e\u9898<\/a><\/h5>\n<p>\u4e00\u5171\u6709 n\u4e2a\u6570\uff0c\u7b2c i \u4e2a\u6570\u662f xi, xi \u53ef\u4ee5\u53d6 [li , ri] \u4e2d\u4efb\u610f\u7684\u4e00\u4e2a\u503c\u3002\u8bbe <code class=\"katex-inline\">S = \\sum{{x_i}^2}<\/code>, \u6c42 S \u79cd\u7c7b\u6570\u3002<br \/>\n\u5206\u7ec4\u80cc\u5305\u95ee\u9898\u3002\u5373\u6bcf\u7ec4\u7269\u54c1\u91cc\u53ea\u80fd\u9009\u51fa\u4e00\u4e2a\u653e\u5165\u80cc\u5305\uff0c\u4e14\u5fc5\u987b\u9009\u4e00\u4e2a\uff0c\u6c42\u6700\u7ec8\u80cc\u5305\u7684\u53ef\u80fd\u53d6\u503c\u3002<br \/>\n\u7528\u4e00\u822c\u7684\u80cc\u5305\u601d\u8def\u89e3\u9898\u7684\u8bdd\uff1a<br \/>\n<code class=\"katex-inline\">f[i][j]\\ \\ |= f[i-1][j-x[i]]<\/code><br \/>\n\u4f46\u662f\u8fd9\u6837\u7684\u8bdd\u65f6\u95f4\u590d\u6742\u5ea6\u592a\u5927\u4e86\uff0c<code class=\"katex-inline\">O(n*max(S)*n)<\/code><br \/>\n\u8003\u8651\u72b6\u6001\u538b\u7f29\uff0c\u7528bitset\u6765\u5b58\u50a8\u6bcf\u4e00\u5c42\u6bcf\u4e2a\u6570\u768401\u60c5\u51b5\u3002<br \/>\n<code class=\"katex-inline\">f[i]\\ \\ |=\\ f[i-1]\\ << x[i]^{2}<\/code><br \/>\n\u501f\u52a9\u4e8ebitset\u65b9\u4fbf\u7684\u4f4d\u8fd0\u7b97\u6765\u5927\u5927\u51cf\u5c0f\u65f6\u95f4\u590d\u6742\u5ea6\uff01<\/p>\n<pre><code class=\"language-c++\">\n#include &lt;bitset&gt;\n#include &lt;iostream&gt;\nusing namespace std;\nint n;\nint l[105], r[105];\nbitset&lt;1000005&gt; f[105];\nint main(){\n    std::ios::sync_with_stdio(false);\n    cin &gt;&gt; n;\n    for (int i=1;i&lt;=n;i++)    cin &gt;&gt; l[i] &gt;&gt; r[i];\n    f[0][0] = 1;\n    for (int i=1;i&lt;=n;i++){\n        for (int j=l[i];j&lt;=r[i];j++){\n            f[i] |= f[i-1]&lt;&lt;(j*j);\n        }\n    }\n    cout &lt;&lt; f[n].count();\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>bitset bitset\u6570\u636e\u7c7b\u578b\uff0c\u5728\\&lt;bitset>\u5934\u6587\u4ef6\u4e2d\uff0c\u662f\u4e00\u79cd\u7c7b\u4f3c\u4e8e\u6570\u7ec4\u548c\u5b57\u7b26\u4e32\u7684\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/567"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=567"}],"version-history":[{"count":27,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/567\/revisions"}],"predecessor-version":[{"id":659,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/567\/revisions\/659"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=567"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}