HDU 3032 Nim or not Nim? (Game, table searching Rules)

Source: Internet
Author: User
Nim or not Nim?

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 540 accepted submission (s): 246

Problem descriptionnim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. on each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.

Nim is usually played as a misere game, in which the player to take the last object loses. nim can also be played as a normal play game, which means that the person who makes the last move (I. E ., who takes the last object) wins. this is called normal play because most games follow this Convention, even though Nim usually does not.

Alice and Bob is tired of playing Nim under the standard rule, so they make a difference by also allowing the player to separate one of the heaps into two smaller ones. that is, each turn the player may either remove any number of objects from a heap or separate a heap into two smaller ones, and the one who takes the last object wins.

 

Inputinput contains multiple test cases. the first line is an integer 1 ≤ T ≤ 100, the number of test cases. each case begins with an integer N, indicating the number of the heaps, the next line contains N integers s [0], s [1],..., s [N-1], representing heaps with s [0], s [1],..., s [N-1] objects respectively. (1 ≤ n ≤ 10 ^ 6, 1 ≤ S [I] ≤ 2 ^ 31-1)

 

Outputfor each test case, output a line which contains either "Alice" or "Bob", which is the winner of this game. Alice will play first. You may asume they never make mistakes.

 

Sample input2
3
2 2 3
2
3 3

 

Sample outputalice
Bob

 

Source2009 multi-university training contest 13-host by hit

 

Recommendgaojie is a type of Nim game. You can read the paper first. In fact, it is to first obtain the SG function, and then the sum of the SG values of N numbers. If it is 0, it is defeated. If it is not zero, it will win. When the SG value is calculated, the table contains 100, and most of them are SG [I] = I. except for I % 4 = 0 then SG [I] = I-1; I % 4 = 3 then SG [I] = I + 1; other SG [I] = I;
 //  ========================================================== ==========================================  //  Name: HDU. cpp //  Author:  //  Version:  //  Copyright: Your copyright notice  //  Description: Hello world in C ++, ANSI-style  //  ========================================================== ==========================================  # Include <Iostream> # Include < String . H># Include <Stdio. h> # Include <Algorithm> Using   Namespace  STD;  /*  Const int maxn = 1010; int SG [maxn]; bool vis [maxn]; int Mex (INT v) {If (SG [v]! =-1) return SG [v]; memset (VIS, false, sizeof (VIS); int TMP; TMP = Mex (0); vis [TMP] = true; for (INT I = 1; I <v; I ++) {TMP = Mex (V-I); vis [TMP] = true; TMP = Mex (I) ^ Mex (V-I); vis [TMP] = true;} For (INT I = 0; I <maxn; I ++) if (vis [I] = false) {SG [v] = I; break;} return SG [v];}  */  Int Mex ( Int  V ){  If (V = 0 ) Return   0  ;  If (V % 4 = 0 ) Return V- 1  ;  If (V % 4 =3 ) Return V + 1  ;  Return  V ;}  Int  Main (){  //  Freopen ("in.txt", "r", stdin );  //  Freopen ("out.txt", "W", stdout );  //  Memset (SG,-1, sizeof (SG ));  // SG [0] = 0;      Int  T;  Int  N; scanf (  "  % D  " ,& T );  While (T -- ) {Scanf (  "  % D  " ,& N );  Int Ans =0  ;  Int  V;  While (N -- ) {Scanf (  "  % D  " ,& V); ans ^ = Mex (V );}  If (ANS = 0 ) Printf ( "  Bob \ n "  );  Else Printf ( "  Alice \ n  "  );}  Return   0  ;} 

 

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.