HDU 3389 Game (ladder game)

Source: Internet
Author: User

Game
Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %i64d &%i64u

Submit Status

Description

Bob and Alice are playing a new game. There is n boxes which has been numbered from 1 to N. Each box is either empty or contains several cards. Bob and Alice move the cards in turn. In each turn the corresponding player should choose a Non-empty box A and choose another box B that B<a && (a+b )%2=1 && (a+b)%3=0. Then, take the arbitrary number (but not zero) of the cards from box A to box B. The last one can do a legal move wins. Alice is the first player. Predict who'll win the game.

Input

The first line contains an integer T (t<=100) indicating the number of test cases. The first line of all test case contains an integer n (1<=n<=10000). The second line has n integers which is not being bigger than 100. The i-th integer indicates the number of cards in the I-th box.

Output

For each test case, print the case number and the winner ' s name Follow the format of the sample output.

Sample Input

221 271 3 3 2 2 1 2

Sample Output

Case 1:alicecase 2:bob

Source

The 5th guangting Cup Central China Invitational Programming Contest Test Instructions: There is a T set of data. There are n boxes for each set of data, and the n boxes are numbered 12345678 .... (note not starting from 0)There is a certain amount of cards in each box. Each time a box with a number B and a number A is required to meet b<a && (a+b)%2=1 && (a+b)%3=0, transfer any number of cards in A to B, who can no longer transfer who loses. Puzzle: Ladder game, only need to consider the number of steps to the odd box, the number of steps for an even box does not need to consider. The box numbered 1,3,4 in the subject cannot transfer the cards and the rest of the boxes can be transferred. For example: 2->1, 5->4, 6->3, 7->2, 8->1, 9->6 ...It is essentially an n-level ladder, which we transfer in the remainder of%3 0->0, 1->2, 2->1;The final resultmust be 1 or 3 or 4, the parity of the number of steps the card transfers in these boxes is certain . Why do you say that? Because even if some boxes such as the Number 11 box, there are 11->4 and 11->10->8->1 two options, but the two selected step number of the parity is the same, are odd, so parity is certain. So we're going to turn this ladder game into a game of Nim, okay? Nim games for boxes with odd number of steps。 Write a few more numbers on the paper or use a table to find the following rules: Box Number modulo 6 is the position of the 0,2,5, the number of moves is odd, the rest is even. It's a good place to be pushed here.
#include <iostream>#include<cstdio>using namespacestd;intMain () {intt,cas=1; CIN>>T;  while(t--)    {        intn,data,ans=0; CIN>>N;  for(intI=1; i<=n;i++) {cin>>data; if(i%6==2|| i%6==5|| i%6==0) ans^=data; }        if(ANS) printf ("Case %d:alice\n", cas++); Elseprintf ("Case %d:bob\n", cas++); }    return 0;}

HDU 3389 Game (ladder game)

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.