Light OJ 1296-again Stone Game

Source: Internet
Author: User

Transmission Door

1296-again Stone Game
PDF (中文版) Statistics Forum
Time Limit: 2 second (s) Memory Limit: MB

Alice and Bob are playing a stone game. Initially there is n piles of stones and each pile contains some stone. Alice stars the game and they alternate moves. In each move, a player have to select any pile and should remove at least one and no more than half stones from that pile. So, for example if a pile contains of stones, then a player can take at least 1 and at the most 5 stones from that pile. If A pile contains 7 stones; At the most 3 stones from this pile can be removed.

Both Alice and Bob play perfectly. The player cannot make a valid move loses. Now you is given the information of the piles and the number of stones in all the piles, you have to find the player who Would win if both play optimally.

Input

Input starts with an integer T (≤100), denoting the number of test cases.

Each case is starts with a line containing an integer n (1≤n≤1000). The next line contains n space separated integers ranging in [1, 109]. The ith integer in this line denotes the number of stones in the ith pile.

Output

For each case, print the case number and the name of the "who'll win the game."

Sample Input Output for Sample Input

5

1

1

3

10 11 12

5

1 2 3) 4 5

2

6 {

3

1 3 9

Case 1:bob

Case 2:alice

Case 3:alice

Case 4:bob

Case 5:alice

Main topic:

There are m heap of stones, each pile of X, two people (Alice and Bob) take turns to operate, each time you can choose any heap, take at least one stone, but do not take more than half of the stone, who can not take who will lose Alice initiator
Problem Solving Ideas:first of all, if you want to ask the SG function, 10^9 must time out, so first ask for the SG value, because each time can only take away more than half of the number of stones, so we can first hit a SG table, the following is the 30-digit SG value:0 1 0 2 1 3 0 4 2 5 1 6 3 7 0 8 4 9 2 10 5 11 1 12 6 13 3 14 7 15,
by observing we can find that even-numbered SG values are half the number of even, when we take out all the even numbers: 01021304251637... is the same as above, so the odd SG value is SG[I/2], and we can do it.

My Code:
#include <iostream> #include <cstdio> #include <cstring>using namespace std;const int maxn = 1e3+5;int    Sg[maxn];int hash[maxn];void Get_sg () {memset (SG, 0, sizeof (SG));        for (int i=1; i<maxn; i++) {memset (hash, 0, sizeof (hash));        for (int j=1; j<=i/2; J + +) {Hash[sg[i-j]] = 1;        } Int J;        for (j=0;; j + +) {if (!hash[j]) break;    } Sg[i] = j; } for (int i=1; i<=30; i++) cout<<sg[i]<< "";}    int main () {///get_sg ();    int T;    scanf ("%d", &t);        for (int cas=1; cas<=t; cas++) {int m, x, ans=0;        scanf ("%d", &m);            for (int i=0; i<m; i++) {scanf ("%d", &x);            while (x&1) x>>=1;        Ans ^= (x>>1);        } if (!ans) printf ("Case%d:bob\n", CAs);    else printf ("Case%d:alice\n", CAs); } return 0;}


Light OJ 1296-again Stone 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.