{"id":1226,"date":"2021-05-15T11:08:12","date_gmt":"2021-05-15T03:08:12","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=1226"},"modified":"2021-05-15T18:18:56","modified_gmt":"2021-05-15T10:18:56","slug":"%e5%8d%9a%e5%bc%88%e8%ae%ba%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2021\/05\/15\/%e5%8d%9a%e5%bc%88%e8%ae%ba%e5%9f%ba%e7%a1%80\/","title":{"rendered":"\u535a\u5f08\u8bba\u57fa\u7840 SG\u51fd\u6570"},"content":{"rendered":"<h3>\u535a\u5f08\u8bba\u57fa\u7840\u548cSG\u51fd\u6570<\/h3>\n<p>\u4e00\u822c\u7684\u535a\u5f08\u8bba\u9898\u76ee\u6ee1\u8db3\u5982\u4e0b\u7279\u70b9\uff1a<\/p>\n<ol>\n<li>\u6709\u4e24\u540d\u9009\u624b\u8fdb\u884c\u56de\u5408\u5236\u6e38\u620f<\/li>\n<li>\u4e24\u540d\u9009\u624b\u90fd\u662f\u6781\u5176\u806a\u660e\u7684\uff0c\u6bcf\u6b21\u90fd\u4f1a\u9009\u62e9\u6700\u4f18\u7684\u65b9\u6848<\/li>\n<li>\u4e24\u540d\u9009\u624b\u6bcf\u8d70\u4e00\u6b65\u90fd\u662f\u5728\u6709\u9650\u7684\u5408\u6cd5\u96c6\u5408\u4e2d\u9009\u53d6\u4e00\u79cd<\/li>\n<li>\u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\uff0c\u5408\u6cd5\u64cd\u4f5c\u53ea\u53d6\u51b3\u4e8e\u60c5\u51b5\u672c\u8eab\uff0c\u4e0e\u9009\u624b\u65e0\u5173<\/li>\n<li>\u6e38\u620f\u7ed3\u675f\u7684\u6761\u4ef6\u4e3a\u5f53\u67d0\u4f4d\u9009\u624b\u8fdb\u884c\u64cd\u4f5c\u65f6\uff0c\u6ca1\u6709\u5408\u6cd5\u7684\u60c5\u51b5\u3002<\/li>\n<\/ol>\n<h4>\u5df4\u4ec0\u535a\u5f08(Bash Game)<\/h4>\n<p>n\u77f3\u5b50\uff0c\u4e24\u4e2a\u4eba\u6bcf\u6b21\u53ef\u4ee5\u53d61~m\u4e2a\uff0c\u95ee\u5148\u624b\u5fc5\u8d62\u8fd8\u662f\u5fc5\u8f93(\u6700\u540e\u53d6\u5149\u8005\u80dc)\u3002<br \/>\n\u540c\u4f59\u5b9a\u7406\uff1a<code>n=k*(m+1)+r<\/code>\uff0c\u5148\u624b\u62ff\u8d70r\u4e2a\uff0c\u7136\u540e\u540e\u624b\u65e0\u8bba\u62ff\u591a\u5c11\u4e2a\uff0c\u5148\u624b\u53ea\u8981\u4fdd\u8bc1\u6bcf\u6b21\u62ff\u5b8c\u4e4b\u540e\u5269\u4e0b\u7684\u77f3\u5b50\u6570\u91cf\u662f<code>(m+1)<\/code>\u7684\u500d\u6570\u5c31\u5fc5\u80dc\u3002\u53cd\u4e4b\uff0c\u82e5\u4e00\u5f00\u59cb<code>n<\/code>\u5c31\u662f<code>m+1<\/code>\u7684\u500d\u6570\uff0c\u5219\u5fc5\u8f93\u3002<\/p>\n<pre><code class=\"language-c++\">if (n%(m+1))    return false;\nreturn true;<\/code><\/pre>\n<h4>\u5a01\u4f50\u592b\u535a\u5f08(Wythoff Game)<\/h4>\n<p>\u6709\u4e24\u5806\u7269\u54c1\uff0c\u4e24\u4e2a\u4eba\u8f6e\u6d41\u4efb\u610f\u4e00\u5806\u4e2d\u81f3\u5c11\u62ff\u4e00\u4e2a\u6216\u8005\u4ece\u4e24\u5806\u62ff\u6570\u91cf\u76f8\u540c\u7684\u7269\u54c1\uff0c\u4e0d\u80fd\u4e0d\u62ff\u3002\u6700\u540e\u53d6\u5149\u8005\u80dc\u3002<\/p>\n<p>\u5148\u624b\u7684\u5fc5\u8f93\u5c40\u52bf\uff1a(0,0),(1,2),(3,5),(4,7),(6,10),(8,13),(9,15),(11,18),(12,20)\u3002\u4ece\u8fd9\u4e9b\u5fc5\u8f93\u5c40\u52bf\u4e2d\u53ef\u4ee5\u53d1\u73b0\uff0c\u6bcf\u7ec4\u7684\u7b2c\u4e00\u4e2a\u90fd\u662f\u524d\u9762\u6ca1\u6709\u51fa\u73b0\u8fc7\u7684\uff0c\u4e14\u6ee1\u8db3\u9ec4\u91d1\u5206\u5272\u6bd4<code class=\"katex-inline\">a_k = [k*\\frac{\\sqrt5+1}{2}], b_k=a_k+k<\/code>\u3002<br \/>\n\u5373\u6ee1\u8db3\u8fd9\u4e2a\u6761\u4ef6\u7684\u8bdd\u5148\u624b\u5fc5\u8f93<\/p>\n<pre><code class=\"language-c++\">double r = (sqrt(5.0)+1)\/2;\nint k = abs(b - a) * r;\nif (k != min(a,b))  return true;\nreturn false;<\/code><\/pre>\n<h4>\u6590\u6ce2\u90a3\u5951\u535a\u5f08(Fibonacci Nim Game)<\/h4>\n<p>\u4e00\u5806\u77f3\u5b50\u6709n\u4e2a\uff0c\u4e24\u4eba\u8f6e\u6d41\u53d6\uff0c\u5148\u53d6\u8005\u7b2c\u4e00\u6b21\u53ef\u4ee5\u53bb\u4efb\u610f\u591a\u4e2a\uff0c\u4f46\u662f\u4e0d\u80fd\u53d6\u5b8c\uff0c\u4ee5\u540e\u6bcf\u6b21\u53d6\u7684\u77f3\u5b50\u6570\u4e0d\u80fd\u8d85\u8fc7\u4e0a\u6b21\u53d6\u5b50\u6570\u76842\u500d\u3002\u53d6\u5b8c\u8005\u80dc\u3002<\/p>\n<p>\u5f53n\u662f\u6590\u6ce2\u90a3\u5951\u6570\u65f6\u5148\u624b\u80dc\u3002<\/p>\n<pre><code class=\"language-c++\">f[0] = f[1] = 1;\nfor (int i = 0; f[i - 1] &lt; n; i++){\n    f[i] = f[i - 1] + f[i - 2];\n    if (f[i] == n)  return true;\n}\nreturn false;<\/code><\/pre>\n<h4>\u5c3c\u59c6\u535a\u5f08(Nim Game)<\/h4>\n<p>\u6709n\u5806\u7269\u54c1\uff0c\u4e24\u4e2a\u4eba\u8f6e\u6d41\u53d6\uff0c\u5728\u4efb\u610f\u4e00\u5806\u4e2d\u53d6\u4e0d\u5c11\u4e8e1\u4e2a\uff0c\u6700\u540e\u53d6\u5b8c\u8005\u80dc\u3002<\/p>\n<p>\u5047\u8bbe\u67093\u5806\u7269\u54c1\uff0c(0,0,0)\u662f\u5fc5\u8d25\u6001\uff0c(0,n,n)\u4e5f\u662f\u5fc5\u8d25\u6001\uff0c\u56e0\u4e3a\u5148\u624b\u65e0\u8bba\u53d6\u591a\u5c11\uff0c\u540e\u624b\u53ea\u8981\u5728\u53e6\u4e00\u5806\u4e2d\u53d6\u540c\u6837\u4e2a\u6570\uff0c\u5c31\u4ecd\u80fd\u4fdd\u6301(0,n,n)\u72b6\u6001\uff0c\u6700\u540e\u4e00\u5b9a\u662f\u540e\u624b\u5148\u53d6\u5b8c\u6240\u6709\u7269\u54c1\u3002\u7136\u540e\u5206\u6790\u53d1\u73b0(1,2,3)\u4e5f\u662f\u5fc5\u8d25\u6001\uff0c\u901a\u8fc7\u4e8c\u8fdb\u5236\u5206\u6790\u53d1\u73b0\uff1a0001^0010^0011=0000\u3002\u53ea\u8981\u8fd9n\u4e2a\u6570\u76f8\u5f02\u6216\u540e\u503c\u4e3a0\u5c31\u662f\u5fc5\u8d25\u6001\uff0c\u5176\u4f59\u90fd\u662f\u5fc5\u80dc\u6001\u3002<\/p>\n<p><strong>\u8bc1\u660e<\/strong>\uff1a\u5047\u8bben\u4e2a\u6570\u7684\u5f02\u6216\u548c\u4e3a0\uff0c\u90a3\u4e48\u5148\u624b\u5fc5\u8d25\u3002\u5f53\u5f02\u6216\u548c\u4e3ak\u65f6\uff0ck\u4e0d\u4e3a0\uff0c\u5219\u5728k\u7684\u4e8c\u8fdb\u5236\u4e0b\u7684\u6700\u9ad8\u4f4d\u4e0a\uff0c\u4e00\u5b9a\u5b58\u5728\u5947\u6570\u4e2a\u6570\u5b57\u5728\u8be5\u6570\u4f4d\u4e3a1\uff0c\u968f\u4fbf\u62ff\u51fa\u4e00\u4e2a\u51fa\u6765x\uff0c\u4ece\u5b83\u8fd9\u5806\u77f3\u5b50\u4e2d\u62ff\u8d70<code>x-x^k<\/code>\u4e2a\uff0c\u5bb9\u6613\u60f3\u5230<code>x^k<\/code>\u662f\u5c0f\u4e8ek\u7684\uff0c\u6240\u4ee5\u8fd9\u4e2a\u64cd\u4f5c\u662f\u5408\u6cd5\u7684\uff0c\u8fd9\u6837\u62ff\u5b8c\u4e4b\u540e\uff0c\u5269\u4e0b\u7684\u6570\u7684\u5f02\u6216\u548c\u5c31\u53d8\u62100\u4e86\uff0c\u8fd9\u6837\u7684\u8bdd\u540e\u624b\u5fc5\u8d25\uff0c\u4e8e\u662f\u5148\u624b\u5fc5\u80dc\u3002\u800c\u5f53\u5f02\u6216\u548c\u4e3a0\u65f6\uff0c\u5148\u624b\u4e0d\u8bba\u600e\u4e48\u62ff\uff0c\u5f97\u5230\u7684\u72b6\u6001\u5f02\u6216\u548c\u4e00\u5b9a\u4e0d\u4e3a0\uff0c\u81ea\u5df1\u5c31\u53d8\u6210\u4e86\u5fc5\u8d25\u6001\uff0c\u4e8e\u662f\u5047\u8bbe\u6210\u7acb\u3002<\/p>\n<pre><code class=\"language-c++\">int x = 0;\nfor (int i:nums)    x ^= i;\nif (x)  return true;\nreturn false;<\/code><\/pre>\n<p>\u4f46\u662f\uff0c\u5b9e\u9645\u95ee\u9898\u4e2d\u4e0d\u53ef\u80fd\u7ed9\u51fa\u5982\u6b64\u6807\u51c6\u7684\u535a\u5f08\u6a21\u578b\uff0c\u5bf9\u4e8e\u66f4\u52a0\u4e00\u822c\u7684\u535a\u5f08\u95ee\u9898\uff0c\u6211\u4eec\u8be5\u5982\u4f55\u6c42\u89e3\u5462\uff1f\u901a\u8fc7SG\u51fd\u6570\u8f6c\u6362\u4e3a\u5c3c\u59c6\u535a\u5f08\u3002<\/p>\n<h4>\u6709\u5411\u56fe\u6e38\u620f\u548cSG\u51fd\u6570<\/h4>\n<p>\u6709\u5411\u56fe\u6e38\u620f\u662f\u4e00\u4e2a\u7ecf\u5178\u7684\u535a\u5f08\u6e38\u620f\uff0c\u5927\u90e8\u5206\u7684\u516c\u5e73\u7ec4\u5408\u6e38\u620f\u90fd\u53ef\u4ee5\u8f6c\u5316\u4e3a\u6709\u5411\u56fe\u6e38\u620f\u3002<\/p>\n<p>\u5728\u4e00\u4e2a\u6709\u5411\u65e0\u73af\u56fe\u4e2d\uff0c\u53ea\u8981\u4e00\u4e2a\u8d77\u70b9\uff0c\u5728\u6700\u4e0a\u9762\uff0c\u7136\u540e\u73a9\u5bb6\u5f00\u59cb\u8f6e\u6d41\u5411\u4e0b\u6cbf\u7740\u8fb9\u63a8\u52a8\u68cb\u5b50\uff0c\u4e0d\u80fd\u8d70\u7684\u73a9\u5bb6\u5224\u8d1f\u3002<br \/>\n\u53ef\u4ee5\u628a\u535a\u5f08\u6e38\u620f\u7684\u6bcf\u4e00\u4e2a\u72b6\u6001\u90fd\u62bd\u8c61\u6210\u4e00\u4e2a\u70b9\uff0c\u800c\u4ece\u8fd9\u4e2a\u72b6\u6001\u53ef\u80fd\u8f6c\u5316\u7684\u5176\u5b83\u7684\u6240\u6709\u72b6\u6001\uff0c\u90fd\u662f\u8fd9\u4e2a\u70b9\u7684\u540e\u7ee7\u72b6\u6001\uff0c\u5c31\u662f\u5b50\u7ed3\u70b9\u3002<\/p>\n<p>\u5b9a\u4e49mex\u51fd\u6570\uff1amex\u51fd\u6570\u7684\u503c\u4e3a\u4e0d\u5c5e\u4e8e\u96c6\u5408S\u4e2d\u7684\u6700\u5c0f\u7684\u975e\u8d1f\u6574\u6570\u503c\u3002<br \/>\n<code class=\"katex-inline\">mex(S) = min{x}(x \\notin S, x \\in N)<\/code><br \/>\n\u4f8b\u5982<code class=\"katex-inline\">mex(\\{0,2,4\\})=1, mex(\\{1,2\\})=0<\/code><br \/>\n\u5bf9\u4e8e\u72b6\u6001x\u548c\u5b83\u7684\u6240\u6709k\u4e2a\u540e\u7ee7\u72b6\u6001<code class=\"katex-inline\">y_1, y_2, y_3\u00b7\u00b7\u00b7y_k<\/code>\uff0c\u5b9a\u4e49SG\u51fd\u6570\uff1a<code class=\"katex-inline\">SG(x) = mex( \\{ SG(y_1), SG(y_2), SG(y_3)\u00b7\u00b7\u00b7SG(y_k)  \\} )<\/code><br \/>\nSG\u51fd\u6570\u7684\u503c\u4e5f\u662f\u4e00\u4e2a\u6574\u6570\u3002<\/p>\n<p>\u5bf9\u4e8e\u7531n\u4e2a\u6709\u5411\u65e0\u73af\u56fe\u7ec4\u5408\u6210\u7684\u7ec4\u5408\u6e38\u620f\uff0c\u5bf9\u4e8e\u5b83\u4eec\u7684n\u4e2a\u8d77\u70b9<code class=\"katex-inline\">s_1,s_2,s_3\u00b7\u00b7\u00b7s_n<\/code>\uff0c\u6709\u5b9a\u7406\uff1a<strong>\u5f53\u4e14\u4ec5\u5f53<code class=\"katex-inline\">SG(s_1) \\bigoplus SG(s_2) \\bigoplus SG(s_3)\u00b7\u00b7\u00b7SG(s_n) \\neq 0<\/code>\u65f6\uff0c\u8fd9\u4e2a\u6e38\u620f\u5148\u624b\u5fc5\u80dc\u3002<\/strong>\u8fd9\u4e2a\u5b9a\u7406\u53eb\u505aSG\u5b9a\u7406\u3002<\/p>\n<p>\u5bf9\u4e8e\u6ca1\u6709\u540e\u7ee7\u72b6\u6001\u7684\u7ec8\u7ed3\u70b9\uff0c\u5b83\u4eec\u662f\u6e38\u620f\u7684\u7ed3\u675f\u72b6\u6001\uff0c\u5e94\u6839\u636e\u6e38\u620f\u7684\u89c4\u5219\u6765\u5b9a\u4e49SG\u51fd\u6570\u7684\u503c\u3002\u5fc5\u8d25\u6001\u503c\u4e3a0\uff0c\u5426\u5219\u4e3a1\u3002<\/p>\n<h4>\u5c06Nim\u6e38\u620f\u8f6c\u5316\u4e3a\u6709\u5411\u56fe\u6e38\u620f<\/h4>\n<p>\u4ecd\u7136\u662f\u5728n\u5806\u77f3\u5b50\u4e2d\u53d6\u77f3\u5b50\uff0c\u6bcf\u6b21\u5728\u4efb\u610f\u4e00\u5806\u4e2d\u53d6\u6b63\u6574\u6570\u4e2a\u3002\u53ef\u4ee5\u5c06\u6709x\u4e2a\u77f3\u5b50\u7684\u5806\u89c6\u4e3a\u7ed3\u70b9x\uff0c\u90a3\u4e48\u5bf9\u4e8e\u90a3\u4e9b\u5c0f\u4e8e\u7b49\u4e8ex\u7684y\uff0c\u90fd\u662fx\u7684\u540e\u7ee7\u7ed3\u70b9\u3002SG(0)=0\uff0c\u4e00\u5806\u6570\u91cf\u4e3a0\u7684\u77f3\u5b50\u4e3a\u5fc5\u8d25\u6001\u3002\u7136\u540e\u53ef\u4ee5\u8f7b\u6613\u63a8\u51faSG(x)=x\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230Nim\u6e38\u620f\u7684\u7ed3\u8bba\u4e86\u3002<\/p>\n<p><a href=\"http:\/\/acm.hdu.edu.cn\/showproblem.php?pid=1536\">S-Nim<\/a><br \/>\n\u6b64\u9898\u4e0d\u540c\u4e8e\u4e00\u822c\u7684Nim\u6e38\u620f\uff0c\u5148\u7ed9\u51fa\u4e00\u4e2a\u96c6\u5408S\uff0cS\u5305\u542b\u4e00\u4e9b\u6574\u6570\uff0cn\u5806\u77f3\u5b50\uff0c\u6bcf\u6b21\u4ece\u4efb\u610f\u4e00\u5806\u4e2d\u62ff\u8d70\u7684\u77f3\u5b50\u6570\u91cf\u5fc5\u987b\u662fS\u4e2d\u7684\u6570\u5b57\uff0c\u6c42\u95ee\u5148\u624b\u8f93\u8d62\u72b6\u6001\u3002<\/p>\n<p>\u5229\u7528SG\u51fd\u6570\uff0cSG(0)=0\uff0c\u7136\u540e\u9010\u4e2a\u6c42SG(i)\uff0c\u6709\u70b9\u7c7b\u4f3c\u80cc\u5305dp\u7684\u6837\u5b50\uff0c\uff0c\u628a\u96c6\u5408S\u4e2d\u7684\u6570\u4e00\u4e2a\u4e00\u4e2a\u62ff\u51fa\u6765\uff0c\u76f8\u5f53\u4e8e\u662f\u679a\u4e3ei\u7684\u5b50\u96c6\uff0c\u7136\u540e\u6c42mex\uff0c\u6700\u540e\u6c42n\u5806\u77f3\u5b50\u7684SG\u5f02\u6216\u548c\u5373\u53ef\u3002\u5f02\u6216\u548c\u4e3a0\u5fc5\u8d25\uff0c\u4e3a1\u5fc5\u80dc\u3002<\/p>\n<pre><code class=\"language-c++\">#include &lt;bits\/stdc++.h&gt;\n\nusing namespace std;\nint k, m, l;\nint S[105], h[105], SG[10005];\nbool vis[100005];\nvoid init() {\n    SG[0] = 0;\n    for (int i=1; i&lt;=10000; i++) {\n        int tmp = -1, t;\n        for (int j=1; j&lt;=k &amp;&amp; i&gt;=S[j]; j++) {\n            t = SG[i-S[j]];\n            tmp = max(tmp, t);\n            vis[t] = 1;\n        }\n        SG[i] = -1;\n        for (int j=0; j&lt;=tmp; j++) {\n            if (vis[j]) {\n                vis[j] = 0;\n                continue;\n            }\n            if (SG[i]==-1)  SG[i] = j;\n        }\n        if (SG[i]==-1)  SG[i] = tmp+1;\n    }\n    return;\n}\n\nint main(){\n    while (~scanf (&quot;%d&quot;, &amp;k) &amp;&amp; k) {\n        for (int i=1; i&lt;=k; i++)    scanf (&quot;%d&quot;, S+i);\n        sort (S+1, S+k+1);\n        init();\n        scanf (&quot;%d&quot;, &amp;m);\n        for (int i=1; i&lt;=m; i++) {\n            int ans = 0, tmp;\n            scanf (&quot;%d&quot;, &amp;l);\n            while (l--) {\n                scanf (&quot;%d&quot;, &amp;tmp);\n                ans ^= SG[tmp];\n            }\n            if (ans==0) putchar(&#039;L&#039;);\n            else putchar(&#039;W&#039;);\n        }\n        putchar(&#039;\\n&#039;);\n    }\n    return 0;\n}<\/code><\/pre>\n<h4>\u8fdb\u9636  \u72b6\u6001\u7684\u5408\u5e76<\/h4>\n<p>\u6211\u4eec\u4e4b\u524d\u5206\u6790\u8fc7\uff0c\u6709\u5411\u65e0\u73af\u56fe\u4e0a\u7684\u4e00\u4e2a\u7ed3\u70b9\u5c31\u76f8\u5f53\u4e8e\u662f\u4e00\u4e2a\u72b6\u6001\uff0c\u4e5f\u5c31\u662f\u8bf4\u8fd9\u4e2a\u72b6\u6001\u7684SG\u51fd\u6570\u503c\uff0c\u5c31\u662f\u4ece\u8fd9\u4e2a\u72b6\u6001\u5f00\u59cb\u535a\u5f08\u7684\u80dc\u8d1f\u72b6\u6001\uff0cSG\u51fd\u6570\u4e3a0\u65f6\uff0c\u5148\u624b\u5fc5\u8d25\uff0c\u5426\u5219\u5148\u624b\u80dc\u3002\u800c\u6709\u7684\u72b6\u6001\u662f\u5176\u5b83\u72b6\u6001\u7684\u5408\u5e76\uff0c\u6bd4\u5982a\u548cb\u662f\u4e24\u4e2a\u72b6\u6001\uff0c\u800c\u7531c\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2aa\u548cb\u5171\u5b58\u7684\u4e00\u4e2a\u72b6\u6001\uff0cab\u4e0d\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u90a3\u4e48\u4ed6\u4fe9\u5171\u5b58\u7684SG\u51fd\u6570\u503c\u4e3a<code class=\"katex-inline\">SG(a) \\bigoplus SG(b)<\/code>\uff0c\u5176\u5b9e\u5c31\u76f8\u5f53\u4e8e\u662f\u4e00\u5f00\u59cb\u5c31\u6709ab\u8fd9\u4e24\u4e2a\u8d77\u70b9\uff0c\u90a3\u4e48\u7ed3\u679c\u5c31\u662f\u5b83\u4eec\u7684\u5f02\u6216\u548c\u3002\u800c\u8fd9\u4e2a\u5f02\u6216\u548c\u5176\u5b9e\u4e5f\u5c31\u662fc\u7684SG\u51fd\u6570\u503c\u3002<\/p>\n<p><a href=\"http:\/\/acm.hdu.edu.cn\/showproblem.php?pid=3980\">HDU3980 Paint Chain<\/a><br \/>\n\u9898\u610f\uff1a\u4e00\u4e32\u73e0\u5b50\uff0cN\u4e2a\uff0c\u4fe9\u4eba\u7ed9\u73e0\u5b50\u6d82\u8272\uff0c\u6bcf\u6b21\u5fc5\u987b\u6d82\u8fde\u7eed\u7684M\u4e2a\uff0c\u95ee\u8c01\u5fc5\u80dc\u3002<\/p>\n<p>\u5206\u6790\uff1a\u6b64\u9898\u6709\u7279\u6b8a\u60c5\u51b5\uff0c\u4e00\u5f00\u59cb\u82e5<code>N&lt;M<\/code>\uff0c\u90a3\u4e48\u5148\u624b\u5c31\u8f93\u4e86\u3002\u8ba8\u8bba\u5176\u5b83\u60c5\u51b5\uff0c\u5148\u624b\u4e00\u5f00\u59cb\u6d82\u5b8cM\u4e2a\u73e0\u5b50\u4e4b\u540e\uff0c\u73e0\u5b50\u53d8\u6210\u4e86\u4e00\u4e32\uff0c\u957f\u5ea6\u4e3aN-M\uff0c\u6211\u4eec\u53ef\u4ee5\u8f6c\u5316\u4e00\u4e0b\u5148\u624b\uff0c\u5e76\u4e14\u628aN\u521d\u59cb\u5316\u4e3aN-M\uff0c\u7136\u540e\u5f00\u59cb\u535a\u5f08\u3002<br \/>\n\u6c42SG(i)\uff0c\u9996\u5148i\u51cf\u53bbM\uff0c\u7136\u540ei-M\u9700\u8981\u5206\u6210\u4e24\u90e8\u5206a\uff0cb\uff0ca+b=i-M\uff0c\u6b64\u65f6ab\u662f\u4e00\u4e2a\u6574\u4f53\uff0c\u800c\u4e0d\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u6240\u4ee5\u8fd9\u4e2a\u6574\u4f53\u72b6\u6001\u7684SG\u51fd\u6570\u503c\u5c31\u662f<code class=\"katex-inline\">SG(a) \\bigoplus SG(b)<\/code>\uff0c\u7136\u540e\u8ba1\u7b97\u51faSG(N)\u5373\u53ef\u5224\u65ad\u51fa\u7b54\u6848\u3002<\/p>\n<pre><code class=\"language-C++\">#include &lt;bits\/stdc++.h&gt;\n\nusing namespace std;\nconst int maxn = 1005;\n\nint N, M, k;\nbool vis[maxn];\nint SG[maxn];\nvoid solve() {\n    for (int i=0; i&lt;=N; i++)    SG[i] = -1;\n    for (int i=0; i&lt;M; i++)     SG[i] = 0;\n    \/\/SG[M] = 1;\n    for (int i=M; i&lt;=N; i++) {\n        int tmp = -1, t;\n        for (int j=0; j&lt;=i-M; j++) {\n            t = SG[j] ^ SG[i-M-j];\n            vis[t] = 1;\n            tmp = max(tmp, t);\n        }\n        for (int j=0; j&lt;=tmp; j++) {\n            if (vis[j]) {\n                vis[j] = 0;\n                continue;\n            }\n            if (SG[i]==-1)  SG[i] = j;\n        }\n        if (SG[i]==-1)  SG[i] = tmp+1;\n    }\n    return;\n}\n\nint main(){\n    scanf (&quot;%d&quot;, &amp;k);\n    for (int c=1; c&lt;=k; c++) {\n        scanf (&quot;%d %d&quot;, &amp;N, &amp;M);\n        if (N &lt; M) {\n            printf (&quot;Case #%d: abcdxyzk\\n&quot;, c);\n            continue;\n        }\n        N -= M;\n\n        solve();\n        if (SG[N])  printf (&quot;Case #%d: abcdxyzk\\n&quot;, c);\n        else    printf (&quot;Case #%d: aekdycoin\\n&quot;, c);\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u535a\u5f08\u8bba\u57fa\u7840\u548cSG\u51fd\u6570 \u4e00\u822c\u7684\u535a\u5f08\u8bba\u9898\u76ee\u6ee1\u8db3\u5982\u4e0b\u7279\u70b9\uff1a \u6709\u4e24\u540d\u9009\u624b\u8fdb\u884c\u56de\u5408\u5236\u6e38\u620f \u4e24\u540d\u9009\u624b\u90fd\u662f\u6781\u5176\u806a\u660e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[60],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1226"}],"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=1226"}],"version-history":[{"count":12,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1226\/revisions"}],"predecessor-version":[{"id":1238,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1226\/revisions\/1238"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=1226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=1226"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=1226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}