{"id":190,"date":"2019-08-09T14:35:00","date_gmt":"2019-08-09T14:35:00","guid":{"rendered":"https:\/\/imwarming.com\/?p=190"},"modified":"2019-08-09T14:35:00","modified_gmt":"2019-08-09T14:35:00","slug":"hdu1536s-nim","status":"publish","type":"post","link":"https:\/\/imwarming.com\/?p=190","title":{"rendered":"hdu1536 S-Nim"},"content":{"rendered":"<p>\u94fe\u63a5\uff1a<a href=\"http:\/\/acm.hdu.edu.cn\/showproblem.php?pid=1536\">http:\/\/acm.hdu.edu.cn\/showproblem.php?pid=1536<\/a><\/p>\n<p>\u5178\u578b\u5c3c\u59c6\u9898\uff0c\u76f4\u63a5sg\u6a21\u677f\u641e<\/p>\n<p>\u4e4b\u524dmex\u8bbe\u4e3aint\uff0c\u600e\u4e48\u90fdte\u8fc7\u4e0d\u4e86\uff0c\u770b\u4e86\u8ba8\u8bba\u4e4b\u540e\u8bf4\u8bbe\u4e3abool\u5c31\u8fc7\u4e86\uff0c\u4f46\u662f\u6211\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\uff0c\u662fbool\u66f4\u5feb\u5417\uff1f\uff1f\uff1f<\/p>\n<p>ac\u4ee3\u7801\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre><span style=\"color: #008080;\"> 1<\/span> #include&lt;cstdio&gt;\n<span style=\"color: #008080;\"> 2<\/span> #include&lt;iostream&gt;\n<span style=\"color: #008080;\"> 3<\/span> #include&lt;cstring&gt;\n<span style=\"color: #008080;\"> 4<\/span> #include&lt;cmath&gt;\n<span style=\"color: #008080;\"> 5<\/span> #include&lt;algorithm&gt;\n<span style=\"color: #008080;\"> 6<\/span> <span style=\"color: #0000ff;\">#define<\/span> maxn 10001\n<span style=\"color: #008080;\"> 7<\/span> <span style=\"color: #0000ff;\">using<\/span> <span style=\"color: #0000ff;\">namespace<\/span><span style=\"color: #000000;\"> std;\n<\/span><span style=\"color: #008080;\"> 8<\/span> <span style=\"color: #0000ff;\">int<\/span> f[maxn],sg[maxn];<span style=\"color: #0000ff;\">bool<\/span><span style=\"color: #000000;\"> mex[maxn];\n<\/span><span style=\"color: #008080;\"> 9<\/span> <span style=\"color: #0000ff;\">void<\/span> getsg(<span style=\"color: #0000ff;\">int<\/span> k,<span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> n){\n<\/span><span style=\"color: #008080;\">10<\/span>     <span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> i,j;\n<\/span><span style=\"color: #008080;\">11<\/span>     memset(sg,<span style=\"color: #800080;\">0<\/span>,<span style=\"color: #0000ff;\">sizeof<\/span><span style=\"color: #000000;\">(sg));\n<\/span><span style=\"color: #008080;\">12<\/span>     <span style=\"color: #0000ff;\">for<\/span>(i=<span style=\"color: #800080;\">1<\/span>;i&lt;=n;i++<span style=\"color: #000000;\">){\n<\/span><span style=\"color: #008080;\">13<\/span>         memset(mex,<span style=\"color: #800080;\">0<\/span>,<span style=\"color: #0000ff;\">sizeof<\/span><span style=\"color: #000000;\">(mex));\n<\/span><span style=\"color: #008080;\">14<\/span>         <span style=\"color: #0000ff;\">for<\/span>(j=<span style=\"color: #800080;\">1<\/span>;f[j]&lt;=i&amp;&amp;j&lt;=k;j++<span style=\"color: #000000;\">)\n<\/span><span style=\"color: #008080;\">15<\/span>             mex[sg[i-f[j]]]=<span style=\"color: #0000ff;\">true<\/span><span style=\"color: #000000;\">;\n<\/span><span style=\"color: #008080;\">16<\/span>         <span style=\"color: #0000ff;\">for<\/span>(j=<span style=\"color: #800080;\">0<\/span>;j&lt;=n;j++<span style=\"color: #000000;\">){\n<\/span><span style=\"color: #008080;\">17<\/span>             <span style=\"color: #0000ff;\">if<\/span>(mex[j]==<span style=\"color: #0000ff;\">false<\/span><span style=\"color: #000000;\">){\n<\/span><span style=\"color: #008080;\">18<\/span>                 sg[i]=<span style=\"color: #000000;\">j;\n<\/span><span style=\"color: #008080;\">19<\/span>                 <span style=\"color: #0000ff;\">break<\/span><span style=\"color: #000000;\">;\n<\/span><span style=\"color: #008080;\">20<\/span> <span style=\"color: #000000;\">            }\n<\/span><span style=\"color: #008080;\">21<\/span> <span style=\"color: #000000;\">        }\n<\/span><span style=\"color: #008080;\">22<\/span> <span style=\"color: #000000;\">    }\n<\/span><span style=\"color: #008080;\">23<\/span> <span style=\"color: #000000;\">}\n<\/span><span style=\"color: #008080;\">24<\/span> <span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> main(){\n<\/span><span style=\"color: #008080;\">25<\/span>     <span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> n,m,k,q,p,t,ans;\n<\/span><span style=\"color: #008080;\">26<\/span>     <span style=\"color: #0000ff;\">while<\/span>(scanf(<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">%d<\/span><span style=\"color: #800000;\">\"<\/span>,&amp;n)&amp;&amp;<span style=\"color: #000000;\">n){\n<\/span><span style=\"color: #008080;\">27<\/span>         <span style=\"color: #0000ff;\">for<\/span>(<span style=\"color: #0000ff;\">int<\/span> i=<span style=\"color: #800080;\">1<\/span>;i&lt;=n;i++<span style=\"color: #000000;\">){\n<\/span><span style=\"color: #008080;\">28<\/span>             scanf(<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">%d<\/span><span style=\"color: #800000;\">\"<\/span>,&amp;<span style=\"color: #000000;\">f[i]);\n<\/span><span style=\"color: #008080;\">29<\/span> <span style=\"color: #000000;\">        }\n<\/span><span style=\"color: #008080;\">30<\/span>         sort(f+<span style=\"color: #800080;\">1<\/span>,f+<span style=\"color: #800080;\">1<\/span>+<span style=\"color: #000000;\">n);\n<\/span><span style=\"color: #008080;\">31<\/span>         getsg(n,<span style=\"color: #800080;\">10001<\/span><span style=\"color: #000000;\">);\n<\/span><span style=\"color: #008080;\">32<\/span>         scanf(<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">%d<\/span><span style=\"color: #800000;\">\"<\/span>,&amp;<span style=\"color: #000000;\">q);\n<\/span><span style=\"color: #008080;\">33<\/span>         <span style=\"color: #0000ff;\">for<\/span>(<span style=\"color: #0000ff;\">int<\/span> i=<span style=\"color: #800080;\">1<\/span>;i&lt;=q;i++<span style=\"color: #000000;\">){\n<\/span><span style=\"color: #008080;\">34<\/span>             ans=<span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">;\n<\/span><span style=\"color: #008080;\">35<\/span>             scanf(<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">%d<\/span><span style=\"color: #800000;\">\"<\/span>,&amp;<span style=\"color: #000000;\">p);\n<\/span><span style=\"color: #008080;\">36<\/span>             <span style=\"color: #0000ff;\">for<\/span>(<span style=\"color: #0000ff;\">int<\/span> j=<span style=\"color: #800080;\">1<\/span>;j&lt;=p;j++<span style=\"color: #000000;\">){\n<\/span><span style=\"color: #008080;\">37<\/span>                 scanf(<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">%d<\/span><span style=\"color: #800000;\">\"<\/span>,&amp;<span style=\"color: #000000;\">t);\n<\/span><span style=\"color: #008080;\">38<\/span>                 ans^=<span style=\"color: #000000;\">sg[t];\n<\/span><span style=\"color: #008080;\">39<\/span> <span style=\"color: #000000;\">            }\n<\/span><span style=\"color: #008080;\">40<\/span>             <span style=\"color: #0000ff;\">if<\/span>(ans==<span style=\"color: #800080;\">0<\/span>)printf(<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">l<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #000000;\">);\n<\/span><span style=\"color: #008080;\">41<\/span>             <span style=\"color: #0000ff;\">else<\/span> printf(<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">w<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #000000;\">);\n<\/span><span style=\"color: #008080;\">42<\/span> <span style=\"color: #000000;\">        }\n<\/span><span style=\"color: #008080;\">43<\/span>         printf(<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">n<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #000000;\">);\n<\/span><span style=\"color: #008080;\">44<\/span> <span style=\"color: #000000;\">    }\n<\/span><span style=\"color: #008080;\">45<\/span>     <span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">;\n<\/span><span style=\"color: #008080;\">46<\/span> }<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u94fe\u63a5\uff1ahttp:\/\/acm.hdu.edu.cn\/showproblem.php?pid=1536  [&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-190","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>hdu1536 S-Nim - imwarming<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/imwarming.com\/?p=190\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"hdu1536 S-Nim - imwarming\" \/>\n<meta property=\"og:description\" content=\"\u94fe\u63a5\uff1ahttp:\/\/acm.hdu.edu.cn\/showproblem.php?pid=1536 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/imwarming.com\/?p=190\" \/>\n<meta property=\"og:site_name\" content=\"imwarming\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-09T14:35:00+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"warming\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/imwarming.com\/#website\",\"url\":\"https:\/\/imwarming.com\/\",\"name\":\"imwarming\",\"description\":\"\u6c38\u8fdc\u5e74\u8f7b\uff0c\u6c38\u8fdc\u70ed\u6cea\u76c8\u7736\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/imwarming.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/imwarming.com\/?p=190#webpage\",\"url\":\"https:\/\/imwarming.com\/?p=190\",\"name\":\"hdu1536 S-Nim - imwarming\",\"isPartOf\":{\"@id\":\"https:\/\/imwarming.com\/#website\"},\"datePublished\":\"2019-08-09T14:35:00+00:00\",\"dateModified\":\"2019-08-09T14:35:00+00:00\",\"author\":{\"@id\":\"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea\"},\"breadcrumb\":{\"@id\":\"https:\/\/imwarming.com\/?p=190#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/imwarming.com\/?p=190\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/imwarming.com\/?p=190#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/imwarming.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"hdu1536 S-Nim\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea\",\"name\":\"warming\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/imwarming.com\/#personlogo\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g\",\"caption\":\"warming\"},\"sameAs\":[\"https:\/\/imwarming.com\"],\"url\":\"https:\/\/imwarming.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"hdu1536 S-Nim - imwarming","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/imwarming.com\/?p=190","og_locale":"zh_CN","og_type":"article","og_title":"hdu1536 S-Nim - imwarming","og_description":"\u94fe\u63a5\uff1ahttp:\/\/acm.hdu.edu.cn\/showproblem.php?pid=1536 [&hellip;]","og_url":"https:\/\/imwarming.com\/?p=190","og_site_name":"imwarming","article_published_time":"2019-08-09T14:35:00+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"warming","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/imwarming.com\/#website","url":"https:\/\/imwarming.com\/","name":"imwarming","description":"\u6c38\u8fdc\u5e74\u8f7b\uff0c\u6c38\u8fdc\u70ed\u6cea\u76c8\u7736","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/imwarming.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"https:\/\/imwarming.com\/?p=190#webpage","url":"https:\/\/imwarming.com\/?p=190","name":"hdu1536 S-Nim - imwarming","isPartOf":{"@id":"https:\/\/imwarming.com\/#website"},"datePublished":"2019-08-09T14:35:00+00:00","dateModified":"2019-08-09T14:35:00+00:00","author":{"@id":"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea"},"breadcrumb":{"@id":"https:\/\/imwarming.com\/?p=190#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/imwarming.com\/?p=190"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/imwarming.com\/?p=190#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/imwarming.com\/"},{"@type":"ListItem","position":2,"name":"hdu1536 S-Nim"}]},{"@type":"Person","@id":"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea","name":"warming","image":{"@type":"ImageObject","@id":"https:\/\/imwarming.com\/#personlogo","inLanguage":"zh-Hans","url":"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g","caption":"warming"},"sameAs":["https:\/\/imwarming.com"],"url":"https:\/\/imwarming.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts\/190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=190"}],"version-history":[{"count":0,"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts\/190\/revisions"}],"wp:attachment":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}