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函数推到即可;

参考代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
int T,n,SG[maxn],x,ans,vis[maxn];
void getSG(int n)
{
for(int i=;i<=n;++i)
{
memset(vis,,sizeof vis);
for(int j=;j*<i;++j) if(i!=j*) vis[SG[j]^SG[i-j]]=;
for(int j=;j<maxn;++j){ if(!vis[j]) { SG[i]=j;break; } }
}
}
int main()
{
scanf("%d",&T);
getSG(maxn);
for(int cas=;cas<=T;++cas)
{
scanf("%d",&n);ans=;
for(int i=;i<=n;++i)
{
scanf("%d",&x);
ans^=SG[x];
}
if(ans) printf("Case %d: Alice\n",cas);
else printf("Case %d: Bob\n",cas);
}
return ;
}

LightOJ1199 Partition Game的更多相关文章

  1. Partition:增加分区

    在关系型 DB中,分区表经常使用DateKey(int 数据类型)作为Partition Column,每个月的数据填充到同一个Partition中,由于在Fore-End呈现的报表大多数是基于Mon ...

  2. Partition:Partiton Scheme是否指定Next Used?

    在SQL Server中,为Partition Scheme多次指定Next Used,不会出错,最后一次指定的FileGroup是Partition Scheme的Next Used,建议,在执行P ...

  3. Partition:分区切换(Switch)

    在SQL Server中,对超级大表做数据归档,使用select和delete命令是十分耗费CPU时间和Disk空间的,SQL Server必须记录相应数量的事务日志,而使用switch操作归档分区表 ...

  4. sql 分组取最新的数据sqlserver巧用row_number和partition by分组取top数据

    SQL Server 2005后之后,引入了row_number()函数,row_number()函数的分组排序功能使这种操作变得非常简单 分组取TOP数据是T-SQL中的常用查询, 如学生信息管理系 ...

  5. Oracle Partition Outer Join 稠化报表

    partition outer join实现将稀疏数据转为稠密数据,举例: with t as (select deptno, job, sum(sal) sum_sal from emp group ...

  6. SQLServer中Partition By 函数的使用

    今天群里看到一个问题,在这里概述下:查询出不同分类下的最新记录.一看这不是很简单的么,要分类那就用Group By;要最新记录就用Order By呗.然后在自己的表中试着做出来: 首先呢我把表中的数据 ...

  7. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  8. [LeetCode] Partition List 划分链表

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  9. 快速排序中的partition函数的枢纽元选择,代码细节,以及其标准实现

    很多笔试面试都喜欢考察快排,叫你手写一个也不是啥事.我很早之前就学了这个,对快速排序的过程是很清楚的.但是最近自己尝试手写,发现之前对算法的细节把握不够精准,很多地方甚至只是大脑中的一个映像,而没有理 ...

随机推荐

  1. 利用JaCoCo统计接口测试中代码覆盖率

    ​        做接口测试,很多时候都会听到,你接口测试的覆盖率是多少?很多人会回答80%,你怎么统计的,他说覆盖了80%的需求.这个回答没有错误,但是片面,我们不能只考虑需求的覆盖率,还有业务的覆 ...

  2. 大宇java面试系列(二):jvm组成部分

    1. 说一下 JVM 的主要组成部分?及其作用? 类加载器(ClassLoader) 运行时数据区(Runtime Data Area) 执行引擎(Execution Engine) 本地库接口(Na ...

  3. docker swarm 过滤器affinity 限制副本不会出现在同一个节点上

    affinity:container!=容器服务名称(可以是正则) 举个例子:stack_ds.yaml # cat stack_dsc.yaml version: '3.0' services: t ...

  4. 安装&卸载Windows服务

    使用.NET Framework的工具InstallUtil.exe. 安装服务 C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.e ...

  5. 创建基于OData的Web API - Knowledge Builder API, Part I:Business Scenario

    在.NET Core 刚刚1.0 RC的时候,我就给OData团队创建过Issue让他们支持ASP.NET Core,然而没有任何有意义的答复. Roadmap for ASP.NET Core 1. ...

  6. [Office] Resources for Office Development

    Office 2013 Document (.chm) download page: http://www.microsoft.com/en-us/download/details.aspx?id=4 ...

  7. C语音中最简单的排序冒泡排序和选择排序代码实现(非指针)

    #include<stdio.h> int main() { int a[5] = { 2,5,7,3,-1 }; int n = sizeof(a) / sizeof(a[0]);//元 ...

  8. SpringSecurity系列之自定义登录验证成功与失败的结果处理

    一.需要自定义登录结果的场景 在我之前的文章中,做过登录验证流程的源码解析.其中比较重要的就是 当我们登录成功的时候,是由AuthenticationSuccessHandler进行登录结果处理,默认 ...

  9. jquery 向页面追加HTML

    jquery 向页面追加HTML append 函数 例子: <div id="append-test"></div> <script type=&q ...

  10. nyoj 23-取石子(一)(博弈)

    23-取石子(一) 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:20 submit:33 题目描述: 一天,TT在寝室闲着无聊,和同寝的人玩起了取 ...