• LightOJ1199 Partition Game


    Alice and Bob are playing a strange game. The rules of the game are:

    1. Initially there are n piles.
    2. A pile is formed by some cells.
    3. Alice starts the game and they alternate turns.
    4. In each tern a player can pick any pile and divide it into two unequal piles.
    5. If a player cannot do so, he/she loses the game.

    Now you are given the number of cells in each of the piles, you have to find the winner of the game if both of them play optimally.

    Input

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

    Each case starts with a line containing an integer n (1 ≤ n ≤ 100). The next line contains n integers, where the ith integer denotes the number of cells in the ith pile. You can assume that the number of cells in each pile is between 1 and 10000.

    Output

    For each case, print the case number and 'Alice' or 'Bob' depending on the winner of the game.

    Sample Input

    3

    1

    4

    3

    1 2 3

    1

    7

    Sample Output

    Case 1: Bob

    Case 2: Alice

    Case 3: Bob

    题解:对于每一个数下一个拆分为 (1,n-1),(2,n-2) ...  个

    SG函数推到即可;

    参考代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 const int maxn=10010;
     5 int T,n,SG[maxn],x,ans,vis[maxn]; 
     6 void getSG(int n)
     7 {
     8     for(int i=1;i<=n;++i)
     9     {
    10         memset(vis,0,sizeof vis);
    11         for(int j=1;j*2<i;++j) if(i!=j*2) vis[SG[j]^SG[i-j]]=1;
    12         for(int j=0;j<maxn;++j){ if(!vis[j]) { SG[i]=j;break; } }
    13     }
    14 }
    15 int main()
    16 {
    17     scanf("%d",&T);
    18     getSG(maxn);
    19     for(int cas=1;cas<=T;++cas)
    20     {
    21         scanf("%d",&n);ans=0;
    22         for(int i=1;i<=n;++i)
    23         {
    24             scanf("%d",&x);
    25             ans^=SG[x];
    26         }
    27         if(ans) printf("Case %d: Alice
    ",cas);
    28         else printf("Case %d: Bob
    ",cas);
    29     }
    30     return 0;    
    31 } 
    View Code
  • 相关阅读:
    shell脚本的分发,测试,查看
    shell 脚本获取cpu信息(转载)
    shell 脚本编写之获取字符串长度(转载)
    service
    关于Linux安装中NAT模式和桥接模式的区别详解(转载)
    kdj
    pod 详解
    k8s基本概念,资源对象
    AliOS Things添加环境变量
    子函数通过一级指针访问二维数组
  • 原文地址:https://www.cnblogs.com/csushl/p/10388784.html
Copyright © 2020-2023  润新知