{"id":830,"date":"2024-12-23T19:11:08","date_gmt":"2024-12-23T11:11:08","guid":{"rendered":"http:\/\/heqiwei.cn\/?p=830"},"modified":"2024-12-23T19:11:08","modified_gmt":"2024-12-23T11:11:08","slug":"%e5%8d%9a%e5%bc%88%e8%ae%ba%e5%85%a5%e9%97%a8%ef%bc%9asg%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/heqiwei.cn\/index.php\/2024\/12\/23\/%e5%8d%9a%e5%bc%88%e8%ae%ba%e5%85%a5%e9%97%a8%ef%bc%9asg%e5%87%bd%e6%95%b0\/","title":{"rendered":"\u535a\u5f08\u8bba\u5165\u95e8\uff1aSG\u51fd\u6570"},"content":{"rendered":"\n<p>SG\u51fd\u6570\u662f\u535a\u5f08\u8bba\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u6280\u5de7\uff0c\u5176\u76f4\u63a5\u542b\u4e49\u4e3a <strong>\u5f53\u524d\u8282\u70b9\u5230\u8ddd\u5176\u6700\u8fd1\u7684\u201c\u5fc5\u8d25\u70b9\u201d\u7684\u8ddd\u79bb<\/strong> \uff0c\u5728\u9762\u5bf9\u591a\u6b21\u535a\u5f08\u53e0\u52a0\u7684\u95ee\u9898\u65f6\uff0c\u53ef\u4ee5\u66f4\u52a0\u9ad8\u6548\u5730\u7528\u4e8e\u8ba1\u7b97\u5f53\u524d\u8282\u70b9\u4e3a\u5fc5\u8d25\u70b9\u8fd8\u662f\u5fc5\u80dc\u70b9\u3002<\/p>\n\n\n\n<p>\u4ee5<a href=\"https:\/\/acm.hdu.edu.cn\/showproblem.php?pid=1848\">Problem &#8211; 1848<\/a>\u4e3a\u4f8b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/heqiwei.cn\/wp-content\/uploads\/2024\/12\/image-1-1024x784.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"784\" data-original=\"http:\/\/heqiwei.cn\/wp-content\/uploads\/2024\/12\/image-1-1024x784.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-832\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<p>AC\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include&lt;algorithm>\n#include&lt;cstring>\nusing namespace std;\nint h1, h2, h3, fi&#91;1002], sg&#91;1002], v&#91;1002];\nvoid getsg(int x)\n{\n    for (int i = 0; i &lt;= x; ++i) \/\/ \u6c42i\u5f20\u724c\u5bf9\u5e94\u7684sg\u503c\n    {\n        memset(v, 0, sizeof(v));\n        for (int j = 1; fi&#91;j] &lt;= i; ++j) \/\/ \u53d6fi&#91;j]\u5f20\u724c\n            v&#91;sg&#91;i - fi&#91;j]]] = 1;\n        for(int j = 0;;++j)\n            if (!v&#91;j])\n            {\n                sg&#91;i] = j;\n                break;\n            }\n    }\n}\nint main()\n{\n    fi&#91;0] = fi&#91;1] = 1;\n    for (int i = 2; i &lt;= 16; i++)\n        fi&#91;i] = fi&#91;i - 1] + fi&#91;i - 2];\n    memset(sg, -1, sizeof(sg));\n    getsg(1000);\n    while (cin >> h1 >> h2 >> h3 &amp;&amp; (h1 || h2 || h3))\n    {\n        if (!(sg&#91;h1] ^ sg&#91;h2] ^ sg&#91;h3])) cout &lt;&lt; \"Nacci\" &lt;&lt; endl;\n        else cout &lt;&lt; \"Fibo\" &lt;&lt; endl;\n    }\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p><strong>SG\u51fd\u6570\u8ba1\u7b97\u8fc7\u7a0b\uff1a<\/strong><\/p>\n\n\n\n<p>\u5047\u5982\u8ba1\u7b97SG[i]\uff0c\u5219\u9700\u8981\u904d\u5386<strong>\u201c\u5f53\u6211\u6709i\u5f20\u724c\u65f6\uff0c\u6240\u6709\u53ef\u4ee5\u53d6\u724c\u7684\u65b9\u5f0f\u201d<\/strong>\uff0c\u5047\u8bbe\u53d6\u724c\u6570\u4e3ax\uff0c\u7136\u540e\u5c06\u6240\u6709\u53ef\u80fd\u7684SG[i &#8211; x]\u7684\u503c\u6392\u9664\uff0c\u6700\u540e\u4ece0\u5f00\u59cb\u904d\u5386\uff0c\u7b2c\u4e00\u4e2a\u9047\u5230\u7684\u672a\u88ab\u6392\u9664\u7684\u503c\u5373\u4e3a\u5f53\u524d\u6240\u6c42\u7684SG[i]\u3002<\/p>\n\n\n\n<p><strong>\u591a\u535a\u5f08\u53e0\u52a0\u65f6\u6c42\u521d\u59cb\u72b6\u6001\u4e3a\u5fc5\u80dc\u70b9\u8fd8\u662f\u5fc5\u8d25\u70b9\uff1a<\/strong><\/p>\n\n\n\n<p>\u5047\u8bbe\u6709\u4e09\u5806\u724c\uff0c\u5206\u522b\u5305\u542ba,b,c\u5f20\u724c\uff0c\u5219\u53ea\u9700\u6c42\u4e09\u8005\u5bf9\u5e94\u7684SG\u503c\u7684\u5f02\u6216\u7ed3\u679c\u5373\u53ef\uff0c\u5373\u82e5SG[a]^SG[b]^SG[c] = 0\uff0c\u5219\u521d\u59cb\u72b6\u6001\u4e3a\u5fc5\u8d25\u70b9\uff0c\u5426\u5219\u4e3a\u5fc5\u80dc\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SG\u51fd\u6570\u662f\u535a\u5f08\u8bba\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u6280\u5de7\uff0c\u5176\u76f4\u63a5\u542b\u4e49\u4e3a \u5f53\u524d\u8282\u70b9\u5230\u8ddd\u5176\u6700\u8fd1\u7684\u201c\u5fc5\u8d25\u70b9\u201d\u7684\u8ddd\u79bb \uff0c\u5728\u9762\u5bf9\u591a\u6b21\u535a\u5f08\u53e0\u52a0\u7684\u95ee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-830","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/posts\/830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/comments?post=830"}],"version-history":[{"count":1,"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/posts\/830\/revisions"}],"predecessor-version":[{"id":833,"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/posts\/830\/revisions\/833"}],"wp:attachment":[{"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/media?parent=830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/categories?post=830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/heqiwei.cn\/index.php\/wp-json\/wp\/v2\/tags?post=830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}