HDU 3032 SG playing table to find the law *

Source: Internet
Author: User

There are n heaps of stones, Alice takes first, each can choose to take a heap of stones in the 1~x (the total number of stones), you can also choose to divide the heap of stones into any two piles. Alice and Bob take turns and take the last stone to victory.

To play the table code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5 using namespacestd;6 Const intn=1000010;7 intSg[n];8 //Note that the S array to sort by from small to large the SG function is initialized to-1 for each collection simply initialize 1 times9 //N is the size of the set S S[i] is an array of special rules that are definedTen ints[ the]; One intSg_dfs (intx) A { -     inti; -     if(sg[x]!=-1) the         returnSg[x]; -     BOOLvis[ the]; -memset (Vis,0,sizeof(Vis)); -      for(inti=x-1; i>=0; i--)//The first type of extraction +Vis[sg_dfs (i)]=1; -      for(i=1; i<=x/2; i++)//Separate Extraction +     { A         intans=0; atans^=Sg_dfs (i); -Ans^=sg_dfs (xi); -vis[ans]=1; -     } -     inte; -      for(i=0;; i++) in         if(!Vis[i]) -         { toE=i; +              Break; -         } the     returnsg[x]=e; * } $ intMain ()Panax Notoginseng { -     intT,n; thescanf"%d",&t); +memset (sg,-1,sizeof(SG)); A      while(t--) the     { +scanf"%d",&n); -         intx; $          for(intI=0; i<n;i++) $         { -scanf"%d",&x); - Sg_dfs (x); theprintf"sg[%d]=%d\n", x,sg[x]); -         }Wuyi          for(intI=0; i<= -; i++){ theprintf"%d:%d\n", I,sg[i]); -             //if (i%10==0) Wu                 //System ("pause"); -         } Aboutprintf"\ n"); $     } -     return 0; -}

After a different or a bit, 2333

HDU 3032 SG playing table to find the law *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.