hihocoder-#1173: Game Game · Nim Games • Three

Source: Internet
Author: User

#1173: Game games · Nim Games • Three time limit: 10000ms single point time limit: 1000ms memory limit: 256MB description

In this game Alice and Bob decided to add a rule to the original NIM game: Each action, not only the choice of a heap to take away any number of stones (at least 1, at most to take out the pile of all the remaining stones), you can also choose to divide a pile of stones into two piles, but do not take away stones. For example, there are a bunch of stones for K, and when Alice or Bob Acts, the stones can be divided into two piles, X, Y, respectively. Meet X+y=k,x,y>0. So if you add this rule, in the case of Alice always, would you please tell if Alice will win or Bob will win according to the stone heap?

Tip: Sprague-grundy

Input

Line 1th: an integer n. Represents the number of gravel heaps. 1≤n≤100
Line 2nd: n integers, and the number of the first integer represents the a[i],1≤a[i]≤20000 of the heap of stones.

Output

Line 1th: A string, if Alice can win the output "Alice", otherwise output "Bob"

Sample input
31 2 4
Sample output
Bob

Play table to find the rules, finish the table is very good to do.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;intg[1010];voidinit () {memset (g,-1,sizeof(g));}intGETSG (intx) {if(g[x]! =-1)returnG[x]; if(x = =0)return 0; if(x = =1)return 1; if(x = =2)return 2; intvis[1010]; memset (Vis,0,sizeof(VIS)); //printf ("Check%d\n", x);    inttot =0;  for(inti =1; i < x; i++) {        intt =0; //printf ("Check%d\n", i);        /*G[i] = GETSG (i); G[x-i] = GETSG (x-i);*/        intA = GETSG (i), B = GETSG (X-i); T^=A; T^=b; //if (x = = 3) printf ("Check%d%d%d\n", T, I, x-i);Vis[a] = vis[b] =1; Vis[t]=1; } Vis[tot]=1; //for (int i = 0; i < x; i++) vis[i] = 1; //vis[x] = 1;     for(inti =0; ; i++)if(!Vis[i])returni;}intMain () {intN;    Init (); //printf ("%d", GETSG (3));     for(inti =1; I <= -; i++) {G[i]=GETSG (i); printf ("%d%d%d\n", I, I%4, G[i]); }    //printf ("%d\n", 1 ^ 2 ^ 1 ^ 2);}
#include <cstdio>using namespacestd;intGETSG (intN) {if(n = =0)return 0; if(n%4==0)returnN-1; Else if(n%4==3)returnn +1; Else returnN;}intMain () {intN;  while(~SCANF ("%d", &N)) {intFlag =0;  for(inti =1; I <= N; i++) {            inttmp; scanf ("%d", &tmp); Flag^=GETSG (TMP); }        if(flag) puts ("Alice"); ElsePuts"Bob"); }}



hihocoder-#1173: Game Game · Nim Games • Three

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.