{"id":450,"date":"2023-01-29T23:02:30","date_gmt":"2023-01-29T15:02:30","guid":{"rendered":"https:\/\/blog.cirno.fun\/?p=450"},"modified":"2024-09-12T09:29:32","modified_gmt":"2024-09-12T01:29:32","slug":"nim%e6%b8%b8%e6%88%8f-%e5%8f%96%e7%9f%b3%e5%ad%90%e6%b8%b8%e6%88%8f","status":"publish","type":"post","link":"https:\/\/blog.sssn.tech\/?p=450","title":{"rendered":"\u7ecf\u5178NIM\u6e38\u620f\/\u53d6\u77f3\u5b50\u6e38\u620f"},"content":{"rendered":"<p>\u4f5c\u4e3a\u535a\u5f08\u8bba\u7b2c\u4e00\u8bfe\u6765\u770b\u4e00\u4e2a\u975e\u5e38\u7ecf\u5178\u6709\u8da3\u7684\u95ee\u9898\u2014\u2014NIM\u6e38\u620f<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2023\/01\/image-1675001573421.png\" alt=\"file\" \/><\/p>\n<p>NIM\u6e38\u620f\u5c5e\u4e8e\u535a\u5f08\u8bba\u4e2d\u7684ICG\u95ee\u9898\uff08\u516c\u5e73\u7ec4\u5408\u6e38\u620f\uff09<\/p>\n<p>ICG\u95ee\u9898\u9700\u8981\u6ee1\u8db3\u4e0b\u9762\u4e09\u70b9<\/p>\n<ol>\n<li>\u7531\u4e24\u540d\u73a9\u5bb6\u4ea4\u66ff\u79fb\u52a8<\/li>\n<li>\u5728\u6e38\u620f\u8fdb\u7a0b\u7684\u4efb\u610f\u65f6\u523b\u53ef\u4ee5\u6267\u884c\u7684\u64cd\u4f5c\u548c\u8f6e\u5230\u54ea\u540d\u73a9\u5bb6\u65e0\u5173<\/li>\n<li>\u4e0d\u80fd\u884c\u52a8\u7684\u73a9\u5bb6\u5224\u8d1f<\/li>\n<\/ol>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u719f\u77e5\u7684\u68cb\u7c7b\u6e38\u620f\u4e0d\u5c5e\u4e8eICG\u6e38\u620f\uff0c\u6bd4\u5982\u56f4\u68cb\u53cc\u65b9\u4e0b\u7684\u68cb\u5b50\u989c\u8272\u4e0d\u540c<\/p>\n<p>NIM\u6e38\u620f\u5c5e\u4e8eICG\u6e38\u620f\u7684\u5178\u4f8b<\/p>\n<p>\u5bf9\u4e8eNIM\u6e38\u620f\uff0c\u6709\u5982\u4e0b\u4f18\u7f8e\u7b80\u6d01\u7684\u7ed3\u8bba\uff1a<\/p>\n<h4>NIM\u6e38\u620f\u5148\u624b\u5fc5\u80dc\uff0c\u5f53\u4e14\u4ec5\u5f53<\/h4>\n<pre><code class=\"language-katex\">a_1 \\oplus a_2 \\oplus ...\\oplus a_n \\ne 0<\/code><\/pre>\n<p>\u4e0b\u9762\u7ed9\u51fa\u7b80\u8981\u7684\u8bc1\u660e<\/p>\n<p>\u8981\u8bc1\u4e0a\u8ff0\u7ed3\u8bba\uff0c\u6211\u4eec\u9700\u8981\u8bc1\u660e\u4ee5\u4e0b\u51e0\u70b9<\/p>\n<ol>\n<li>\u5f53\u6240\u6709\u77f3\u5b50\u5f02\u6216\u548c\u4e0d\u4e3a0\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e00\u6b21\u5408\u6cd5\u64cd\u4f5c\u4ee4\u5176\u5f02\u6216\u548c\u4e3a0<\/li>\n<li>\u5f53\u6240\u6709\u77f3\u5b50\u5f02\u6216\u548c\u4e3a0\u65f6\uff0c\u5148\u624b\u65e0\u8bba\u5982\u4f55\u53d6\uff0c\u90fd\u4e0d\u80fd\u4ee4\u5176\u5f02\u6216\u548c\u4fdd\u63010<\/li>\n<li>\u5f53\u6240\u6709\u77f3\u5b50\u88ab\u53d6\u5b8c\u65f6\uff0c\u5148\u624b\u5fc5\u8d25\uff08\u663e\u7136\u6210\u7acb\uff09<\/li>\n<\/ol>\n<h4>\u5bf9\u7b2c\u4e00\u70b9\u7684\u8bc1\u660e\uff1a<\/h4>\n<blockquote>\n<p>\u5f53\u6240\u6709\u77f3\u5b50\u5f02\u6216\u548c\u4e0d\u4e3a0\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e00\u6b21\u5408\u6cd5\u64cd\u4f5c\u4ee4\u5176\u5f02\u6216\u548c\u4e3a0<\/p>\n<\/blockquote>\n<p>\u5047\u8bbe<\/p>\n<pre><code class=\"language-katex\">x = a_1 \\oplus a_2 \\oplus ...\\oplus a_n \\ne 0<\/code><\/pre>\n<p>\u6211\u4eec\u5173\u6ce8x<strong>\u4e8c\u8fdb\u5236\u4f4d\u6700\u9ad8\u76841\uff0c\u8bbe\u4e3a\u7b2ck\u4f4d<\/strong>\uff0c\u6709\u5982\u4e0b\u7ed3\u8bba\uff1a<strong>\u5bf9\u4e8e\u6240\u6709\u7684ai\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a\u4e8c\u8fdb\u5236\u4e0b\u7b2ck\u4f4d\u662f1<\/strong><\/p>\n<p>\u56e0\u4e3a\u7531\u5f02\u6216\u7684\u6027\u8d28\u53ef\u77e5\u5982\u679c a xor b = 1\uff0c\u5219ab\u5fc5\u6709\u4e00\u4e2a1<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u505a\u51fa\u4e00\u6b21\u5408\u6cd5\u64cd\u4f5c\u4ee4\u4e0a\u8ff0\u4e8c\u8fdb\u5236\u7b2ck\u4f4d\u4e3a1\u7684a_i\u8f6c\u53d8\u4e3aa_i xor x<\/p>\n<p>\u6b64\u65f6\u524d\u540e\u72b6\u6001\u6539\u53d8\u4e3a<\/p>\n<pre><code class=\"language-katex\">x = a_1 \\oplus a_2 \\oplus ...\\oplus a_k \\oplus ...\\oplus a_n \\ne 0 \\\\\nx&#039; = a_1 \\oplus a_2 \\oplus ...\\oplus a_k \\oplus x \\oplus ...\\oplus a_n = x \\oplus x=0<\/code><\/pre>\n<p>\u800c\u4e3a\u4ec0\u4e48\u8fd9\u4e00\u6b21\u64cd\u4f5c\u662f\u5408\u6cd5\u7684\u5462\uff1f \u89c2\u5bdf\u4e8c\u8fdb\u5236\u4e0bai xor x \u7684\u8fc7\u7a0b\u53ef\u4ee5\u53d1\u73b0 <img decoding=\"async\" src=\"https:\/\/blog.cirno.fun\/wp-content\/uploads\/2023\/01\/image-1677718899686.png\" alt=\"file\" \/>\u56e0\u4e3ax\u5728\u7b2ck\u4f4d\u524d\u90fd\u662f0\uff0c\u6240\u4ee5a_i\\&#8217;\u5728\u7b2ck\u4f4d\u524d\u4fdd\u7559\u4e86ai\u5bf9\u5e94\u4f4d\u7f6e\u7684\u90e8\u5206<\/p>\n<p>\u800c\u7b2ck\u4f4d\u5df2\u7ecf\u8bc1\u660e\u4e8c\u8005\u90fd\u662f1\uff0cxor\u7ed3\u679c\u662f0\uff0c\u6240\u4ee5\u540e\u9762\u7684\u6570\u5b57\u4e0d\u7528\u518d\u5173\u5fc3(\u56fe\u4e2d\u5199\u95ee\u53f7\u7684\u4f4d\u7f6e\u662f0\u6216\u80051\u90fd\u4e0e\u7ed3\u679c\u65e0\u5173)\uff0c\u56e0\u4e3a<strong>a_i\\&#8217;\u4e00\u5b9a\u6bd4a_i\u8981\u5c0f<\/strong>\u4e5f\u5c31\u662f\u6211\u4eec\u4e00\u5b9a\u53ef\u4ee5\u53d6\u8d70ai\u7684\u4e00\u90e8\u5206\u77f3\u5b50\uff0c\u4ee4a_i\u53d8\u4e3aa_i\\'(ai xor x)\uff0c\u6b64\u65f6\u6240\u6709\u77f3\u5b50\u7684\u5f02\u6216\u548c(x)\u4e3a0<\/p>\n<h4>\u73b0\u5728\u8bc1\u660e\u7b2c\u4e8c\u70b9\uff1a<\/h4>\n<blockquote>\n<p>\u5f53\u6240\u6709\u77f3\u5b50\u5f02\u6216\u548c\u4e3a0\u65f6\uff0c\u5148\u624b\u65e0\u8bba\u5982\u4f55\u53d6\uff0c\u90fd\u4e0d\u80fd\u4ee4\u5176\u5f02\u6216\u548c\u4fdd\u63010<\/p>\n<\/blockquote>\n<p>\u6211\u4eec\u53ef\u4ee5\u7528\u53cd\u8bc1\u6cd5\uff1a \u5047\u8bbe\u73b0\u5728\u6709a1~an\u5176\u5f02\u6216\u548c\u4e3a0\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e00\u6b21\u5bf9ai\u7684\u64cd\u4f5c\uff0c\u4ee4\u64cd\u4f5c\u540e\u7684\u77f3\u5b50\u5f02\u6216\u548c\u4ecd\u672a0 \u5373<\/p>\n<pre><code class=\"language-katex\">x = a_1 \\oplus a_2 \\oplus ...\\oplus a_i \\oplus ...\\oplus a_n = 0 \\\\\nx&#039; = a_1 \\oplus a_2 \\oplus ...\\oplus a_i&#039; \\oplus ...\\oplus a_n = 0<\/code><\/pre>\n<p>\u5c06\u7b49\u5f0f\u4e24\u8fb9\u5206\u522b\u5f02\u6216,\u6210\u5bf9\u7684\u6570\u503c\u6d88\u53bb\uff0c\u53ef\u5f97<\/p>\n<pre><code class=\"language-katex\">a_i \\oplus a_i&#039; = 0 \\oplus 0 = 0<\/code><\/pre>\n<p>\u5373<\/p>\n<pre><code class=\"language-katex\">a_i = a_i&#039;<\/code><\/pre>\n<p>\u4e0e\u5047\u8bbe\u77db\u76fe\uff0c\u6545\u5047\u8bbe\u4e0d\u6210\u7acb<\/p>\n<hr \/>\n<hr \/>\n<p>\u81f3\u6b64\u6211\u4eec\u5df2\u7ecf\u8bc1\u660e\u4e86\u8be5\u7ed3\u8bba\u7684\u6b63\u786e\u6027<\/p>\n<p>\u73b0\u5728\u6765\u6b63\u5411\u8fc7\u4e00\u904dNIM\u6e38\u620f\u7684\u601d\u8def\u5427<\/p>\n<ol>\n<li>NIM\u6e38\u620f\u5f53\u4e14\u4ec5\u5f53\u6240\u6709\u77f3\u5b50\u5f02\u6216\u548c\u4e0d\u4e3a0\u65f6\u5148\u624b\u5fc5\u80dc<\/li>\n<li>\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u5148\u624b\u8981\u505a\u51fa\u4e00\u6b21\u64cd\u4f5c\u4ee4\u5176\u5f02\u6216\u548c\u4e3a0\uff0c\u800c\u5bf9\u624b\u65e0\u8bba\u5982\u4f55\u64cd\u4f5c\u90fd\u4e0d\u80fd\u4f7f\u5f02\u6216\u548c\u4fdd\u6301\u4e3a0<\/li>\n<li>\u8fd9\u4f1a\u4f7f\u5f97\u6e38\u620f\u50cf\u6240\u6709\u77f3\u5b50\u5806\u90fd\u4e3a0\u7684\u65b9\u5411\u6536\u675f\u5e76\u6700\u7ec8\u80dc\u5229<\/li>\n<li>\u6211\u4eec\u505a\u51fa\u7684\u64cd\u4f5c\u662f\u53d6\u51fa\u5f53\u4e14\u4e0d\u4e3a\u96f6\u7684\u5f02\u6216\u548cx\u7684\u4e8c\u8fdb\u5236\u6700\u9ad8\u4f4d1\uff0c\u8bb0\u4e3a\u7b2ck\u4f4d\uff0c\u7136\u540e\u627e\u51fa\u4e00\u4e2a\u4e8c\u8fdb\u5236\u7b2ck\u4f4d\u540c\u4e3a1\u7684a_i\uff0c\u4ee4\u4ed6\u53d8\u4e3aa_i xor x<\/li>\n<li>a_i xor x \u4e00\u5b9a\u4f1a\u6bd4a_i\u5c0f\uff0c\u6240\u4ee5\u8fd9\u6b21\u64cd\u4f5c\u662f\u5408\u6cd5\u7684<\/li>\n<\/ol>\n<p>\u4e0a\u4ee3\u7801<\/p>\n<pre><code class=\"language-cpp\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nint main()\n{\n    int res = 0;\n    int n;\n    cin &gt;&gt; n;\n    for(int i = 1; i &lt;= n; i++)\n    {\n        int x;\n        cin &gt;&gt; x;\n        res ^= x;\n    }\n    if(res)\n        puts(&quot;Yes&quot;);\n    else\n        puts(&quot;No&quot;);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u4e3a\u535a\u5f08\u8bba\u7b2c\u4e00\u8bfe\u6765\u770b\u4e00\u4e2a\u975e\u5e38\u7ecf\u5178\u6709\u8da3\u7684\u95ee\u9898\u2014\u2014NIM\u6e38\u620f NIM\u6e38\u620f\u5c5e\u4e8e\u535a\u5f08\u8bba\u4e2d [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,10,13,16],"tags":[],"class_list":["post-450","post","type-post","status-publish","format-standard","hentry","category-nim","category-10","category-13","category-16"],"_links":{"self":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=450"}],"version-history":[{"count":2,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/450\/revisions"}],"predecessor-version":[{"id":728,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/450\/revisions\/728"}],"wp:attachment":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}