zoukankan      html  css  js  c++  java
  • Again Stone Game

    Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains some stone. Alice stars the game and they alternate moves. In each move, a player has 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 10 stones, then a player can take at least 1 and at most 5 stones from that pile. If a pile contains 7 stones; at most 3 stones from that pile can be removed.

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

    Input

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

    Each case 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 player who will win the game.

    Sample Input

    5

    1

    1

    3

    10 11 12

    5

    1 2 3 4 5

    2

    4 9

    3

    1 3 9

    Sample Output

    Case 1: Bob

    Case 2: Alice

    Case 3: Alice

    Case 4: Bob

    Case 5: Alice

    /*
    * @Author: lyuc
    * @Date:   2017-04-26 21:32:51
    * @Last Modified by:   lyuc
    * @Last Modified time: 2017-04-26 22:13:13
    */
    
    /*题意:给你n堆石子每次你可以选择一堆,至少取一个,最多不能超过一半,比如7个的时候,你最多取3个谁不
     *     能取了就输了
     *
     *初步思路:想到了SG,但是没办法数据量太大了,只能打表找规律,找到规律,如果n为奇数sg(n)=sg(n/2)
     *    如果是偶数sg(n)=n/2
     */
    #include <bits/stdc++.h>
    using namespace std;
    int t,n;
    int num;
    int sg[1005];
    int hash[1005];
    int res;
    //sg打表
    void init(){
        memset(sg,0,sizeof sg);
        for(int i=1;i<1005;i++){
            memset(hash,0,sizeof hash);
            for(int j=1;j+j<=i;j++){
                hash[sg[i-j]]=1;
            }
            for(int j=0;j<1005;j++){
                if(hash[j]==0){
                    sg[i]=j;
                    break;
                }
            }
        }
    }
    int main(){
        // freopen("in.txt","r",stdin);
        scanf("%d",&t);
        for(int ca=1;ca<=t;ca++){
            printf("Case %d: ",ca);
            res=0;
            scanf("%d",&n);
            for(int i=0;i<n;i++){
                scanf("%d",&num);
                while(num%2!=0){
                    num/=2;
                }
                res^=num;
            }
            printf(res==0?"Bob
    ":"Alice
    ");
        }
        return 0;
    }
  • 相关阅读:
    您还在用下一步下一步的方式安装SQLSERVER和SQLSERVER补丁吗?
    SQLSERVER误删除了Windows登录用户验证方式使用Windows身份验证的解决方法
    批量解密SQLSERVER数据库中的各种对象的工具dbForge SQL Decryptor
    SQLSERVER将数据移到另一个文件组之后清空文件组并删除文件组
    SQLSERVER群集故障转移笔记
    兼容,原来在这里就已经開始--------Day34
    Objective-C的对象模型和runtime机制
    CF B. Kolya and Tandem Repeat
    循环队列的实现
    LintCode 子树
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6771355.html
Copyright © 2011-2022 走看看