{"id":103,"date":"2024-01-29T23:40:42","date_gmt":"2024-01-29T15:40:42","guid":{"rendered":"https:\/\/linxce.ink\/?p=103"},"modified":"2024-01-30T00:16:35","modified_gmt":"2024-01-29T16:16:35","slug":"%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/linxce.ink\/index.php\/%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0\/%e5%85%a8%e9%83%a8\/acm\/","title":{"rendered":"\u5e38\u7528\u51fd\u6570"},"content":{"rendered":"<h3>max\u548cmin<\/h3>\n<pre><code class=\"language-c++\" lang=\"c++\">max(a, b); min(a, b); max({a, b, c}); min({a, b, c});\r\n<\/code><\/pre>\n<h3>sort<\/h3>\n<pre><code class=\"language-c++\" lang=\"c++\">\/\/\u7528\u6cd5\r\nsort(begin, end);\r\n\/\/\u81ea\u5b9a\u4e49\u6392\u5e8f\r\nbool cmp(int x1,int x2) { return x1 &lt; x2; }\r\nsort(arr, arr + n, cmp);\r\n\/\/Lambda\u8868\u8fbe\u5f0f\r\nsort(arr, arr + n, [](int x1, int x2){ return x1 &lt; x2; });\r\n<\/code><\/pre>\n<h3>\u4e8c\u5206\u67e5\u627e<\/h3>\n<h4>binary_search<\/h4>\n<pre><code class=\"language-cc\" lang=\"cc\">bool flag = binary_search(arr + l, arr + r, val); \/\/\u67e5[l, r),\u627e\u5230\u7ed3\u679c\u4e3atrue\uff0c\u6ca1\u6709\u5219\u4e3afalse\r\n\/\/binary_search\u5229\u7528\u7684\u4e5f\u662f\u6307\u9488\r\n<\/code><\/pre>\n<h4>lower_bound<\/h4>\n<pre><code class=\"language-cc\" lang=\"cc\">lower_bound(arr + l, arr + r, val) \/\/\u627e\u5230[l, r)\u7b2c\u4e00\u4e2a\u5927\u4e8e\u7b49\u4e8eval\u7684\u6570\r\n\/\/\u8fd4\u56de\u5730\u5740,\u5982\u679c\u8fd4\u56de\u5c3e\u5730\u5740,\u5219\u6ca1\u627e\u5230\r\n<\/code><\/pre>\n<h4>upper_bound<\/h4>\n<pre><code class=\"language-cc\" lang=\"cc\">upper_bound(arr + l, arr + r, val) \/\/\u627e\u5230[l, r)\u7b2c\u4e00\u4e2a\u4e25\u683c\u5927\u4e8eval\u7684\u6570\r\n\/\/\u8fd4\u56de\u5730\u5740,\u5982\u679c\u8fd4\u56de\u5c3e\u5730\u5740,\u5219\u6ca1\u627e\u5230\r\n<\/code><\/pre>\n<h4>equal_range<\/h4>\n<p>equal_range\u7efc\u5408\u4e86lower_bound\u548cupper_bound<\/p>\n<pre><code class=\"language-c++\" lang=\"c++\">pair&lt;T, T&gt; = equal_range(arr + l, arr + r, val); \/\/\u8fd4\u56depair\u7c7b\u578b\r\n\/\/\u7b49\u4ef7\u4e8e{lower_bound(arr + l, arr + r, val) ,upper_bound(arr + l, arr + r, val)}\r\n<\/code><\/pre>\n<h3>copy<\/h3>\n<pre><code class=\"language-c++\" lang=\"c++\">copy(arr1 + l, arr1 + r, arr2); \/\/\u628aarr1[l, r)\u7684\u90e8\u5206\u590d\u5236\u5230arr2\r\n<\/code><\/pre>\n<h3>copy_n<\/h3>\n<pre><code class=\"language-c++\" lang=\"c++\">copy_n(arr1 + l, x, arr2); \/\/\u628aarr1[l, l + x)\u7684\u90e8\u5206\u590d\u5236\u5230arr2\r\n<\/code><\/pre>\n<h3>swap<\/h3>\n<pre><code class=\"language-cc\" lang=\"cc\">swap(a, b); \/\/\u4ea4\u6362a, b\r\n<\/code><\/pre>\n<h3>replace<\/h3>\n<pre><code class=\"language-cc\" lang=\"cc\">replace(arr + l, arr + r, oldV, newV); \/\/\u628a[l, r)\u533a\u95f4\u7684oldV\u5168\u90e8\u66ff\u6362\u4e3anewV\r\n<\/code><\/pre>\n<h3>fill<\/h3>\n<pre><code class=\"language-cc\" lang=\"cc\">fill(arr + l, arr + r, val); \/\/\u628a[l, r)\u533a\u95f4\u8d4b\u503c\u4e3aval\r\n<\/code><\/pre>\n<h3>reverse<\/h3>\n<pre><code class=\"language-cc\" lang=\"cc\">reverse(arr + l, arr + r); \/\/\u628a[l, r)\u533a\u95f4\u53cd\u8f6c\r\n<\/code><\/pre>\n<h3>rotate<\/h3>\n<pre><code class=\"language-cc\" lang=\"cc\">rotate(arr + l, arr + mid, arr + r); \/\/\u6eda\u52a8\u6570\u7ec4,arr + mid\u5411\u524d\u6eda\u52a8,\u6210\u4e3a\u65b0\u7684[l, r)\u533a\u95f4\u9996\u5143\u7d20\r\n<\/code><\/pre>\n<h3>find<\/h3>\n<pre><code class=\"language-cc\" lang=\"cc\">find(arr + l, arr + r, val); \/\/\u53ef\u7528\u4e8e\u5bf9\u65e0\u5e8f\u6570\u7ec4\u67e5\u627e\r\n\/\/\u8fd4\u56de\u5730\u5740,\u5982\u679c\u8fd4\u56de\u5c3e\u5730\u5740,\u5219\u6ca1\u627e\u5230\r\n<\/code><\/pre>\n<h3>find_end<\/h3>\n<pre><code class=\"language-c++\" lang=\"c++\">find_end(arr1 + l, arr1 + r, arr2 + l, arr2 + r); \/\/\u67e5\u8be2arr1\u4e2d\u662f\u5426\u6709\u5b50\u6570\u7ec4arr2\r\n\/\/\u8fd4\u56de\u5730\u5740,\u5982\u679c\u8fd4\u56de\u5c3e\u5730\u5740,\u5219\u6ca1\u627e\u5230\r\n<\/code><\/pre>\n<h3>unique<\/h3>\n<p>unique\u7684\u4f5c\u7528\u662f\u201c\u53bb\u6389\u201d\u5bb9\u5668\u4e2d\u76f8\u90bb\u5143\u7d20\u7684\u91cd\u590d\u5143\u7d20<\/p>\n<p>\u5b83\u5b9e\u8d28\u4e0a\u662f\u4e00\u4e2a\u4f2a\u53bb\u9664\uff0c\u5b83\u4f1a\u628a\u91cd\u590d\u7684\u5143\u7d20\u6dfb\u52a0\u5230\u5bb9\u5668\u672b\u5c3e\uff0c\u800c\u8fd4\u56de\u503c\u662f\u53bb\u91cd\u90e8\u5206\u7684\u5c3e\u5730\u5740<\/p>\n<blockquote><p>\u26a0 unique\u9488\u5bf9\u7684\u662f\u76f8\u90bb\u5143\u7d20\uff0c\u6240\u4ee5\u5bf9\u4e8e\u987a\u5e8f\u9519\u4e71\u7684\u6570\u7ec4\u6210\u5458\uff0c\u6216\u8005\u5bb9\u5668\u6210\u5458\uff0c\u9700\u8981\u5148\u8fdb\u884c\u6392\u5e8f<\/p><\/blockquote>\n<pre><code class=\"language-cc\" lang=\"cc\">unique(a.begin(), a.end()); \/\/\u53bb\u91cd\uff0c\u5c06\u91cd\u590d\u5143\u7d20\u653e\u5728\u672b\u5c3e\r\n<\/code><\/pre>\n<h3>count<\/h3>\n<pre><code class=\"language-c++\" lang=\"c++\">auto cnt = count(arr + l, arr + r, val); \/\/\u7edf\u8ba1[l, r)\u4e2dval\u7684\u4e2a\u6570\r\n<\/code><\/pre>\n<h3>equal<\/h3>\n<pre><code class=\"language-c++\" lang=\"c++\">bool flag = equal(arr1 + l, arr1 + r, arr2); \/\/arr1\u7684[l, r)\u533a\u95f4\u662f\u5426\u4e0earr2\u76f8\u7b49\r\n\/\/\u627e\u5230\u7ed3\u679c\u4e3atrue\uff0c\u6ca1\u6709\u5219\u4e3afalse\r\n<\/code><\/pre>\n<h3>merge<\/h3>\n<pre><code class=\"language-cc\" lang=\"cc\">merge(arr1, arr1 + n, arr2, arr2 + m, arr3); \/\/\u5c06arr1,arr2\u6709\u5e8f\u5408\u5e76\u4e3aarr3,\u5f52\u5e76\u6392\u5e8f\r\n<\/code><\/pre>\n<h3>includes<\/h3>\n<pre><code class=\"language-cc\" lang=\"cc\">includes(arr1 + l, arr1 + r, arr2 + l, arr2 + r); \/\/\u67e5\u8be2arr1\u4e2d\u662f\u5426\u6709\u5b50\u5e8f\u5217arr2\r\n<\/code><\/pre>\n<h3>\u96c6\u5408\u76f8\u5173<\/h3>\n<h4>set_union<\/h4>\n<p>\u5176\u4f5c\u7528\u662f\u6c42\u4e24\u4e2a\u96c6\u5408\u7684\u5e76\u96c6\uff0c\u4f46\u662f\u8981\u6c42\u8f93\u5165\u7684\u4e24\u4e2a\u96c6\u5408\u5fc5\u987b\u662f\u6709\u5e8f\u7684<\/p>\n<pre><code class=\"language-cc\" lang=\"cc\">int len = set_union(arr1, arr1 + n1, arr2, arr2 + n2, arr3) - arr3;\r\n\/\/\u8fd4\u56de\u65b0\u96c6\u5408\u5927\u5c0f\r\n<\/code><\/pre>\n<h4>set_intersection<\/h4>\n<p>\u5176\u4f5c\u7528\u662f\u6c42\u4e24\u4e2a\u96c6\u5408\u7684\u4ea4\u96c6\uff0c\u4f46\u662f\u8981\u6c42\u8f93\u5165\u7684\u4e24\u4e2a\u96c6\u5408\u5fc5\u987b\u662f\u6709\u5e8f\u7684<\/p>\n<pre><code class=\"language-cc\" lang=\"cc\">int len = set_intersection(arr1, arr1 + n1, arr2, arr2 + n2, arr3) - arr3;\r\n\/\/\u8fd4\u56de\u65b0\u96c6\u5408\u5927\u5c0f\r\n<\/code><\/pre>\n<h4>set_difference<\/h4>\n<p>\u5176\u4f5c\u7528\u662f\u6c42\u4e24\u4e2a\u96c6\u5408\u7684\u5dee\uff08A - B\uff09\uff0c\u4f46\u662f\u8981\u6c42\u8f93\u5165\u7684\u4e24\u4e2a\u96c6\u5408\u5fc5\u987b\u662f\u6709\u5e8f\u7684<\/p>\n<pre><code class=\"language-cc\" lang=\"cc\">int len = set_difference(arr1, arr1 + n1, arr2, arr2 + n2, arr3) - arr3;\r\n\/\/\u8fd4\u56de\u65b0\u96c6\u5408\u5927\u5c0f\r\n<\/code><\/pre>\n<h4>set_symmetric_difference<\/h4>\n<p>\u5176\u4f5c\u7528\u662f\u6c42\u4e24\u4e2a\u96c6\u5408\u7684\u5bf9\u79f0\u5dee\u96c6 <em>A<\/em> \u25b3<em>B<\/em> = ( <em>A<\/em> \u2014<em>B<\/em> )\u222a( <em>B<\/em> \u2014<em>A<\/em> ) \uff0c\u4f46\u662f\u8981\u6c42\u8f93\u5165\u7684\u4e24\u4e2a\u96c6\u5408\u5fc5\u987b\u662f\u6709\u5e8f\u7684<\/p>\n<pre><code class=\"language-cc\" lang=\"cc\">int len = set_symmetric_difference(arr1, arr1 + n1, arr2, arr2 + n2, arr3) - arr3;\r\n\/\/\u8fd4\u56de\u65b0\u96c6\u5408\u5927\u5c0f\r\n<\/code><\/pre>\n<h3>\u5b57\u5178\u5e8f\u51fd\u6570<\/h3>\n<h4>next_permutation<\/h4>\n<pre><code class=\"language-cc\" lang=\"cc\">next_permutation(arr ,arr + n); \/\/\u5f97\u5230\u4e0b\u4e2a\u4e00\u4e2a\u5b57\u5178\u5e8f\r\n<\/code><\/pre>\n<h4>prev_permutation<\/h4>\n<pre><code class=\"language-cc\" lang=\"cc\">prev_permutation(arr ,arr + n); \/\/\u5f97\u5230\u4e0a\u4e2a\u4e00\u4e2a\u5b57\u5178\u5e8f\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>max\u548cmin max(a, b&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,12],"tags":[7],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-acm","category-12","tag-cpp"],"_links":{"self":[{"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":6,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":109,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions\/109"}],"wp:attachment":[{"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}