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. javascript jquery 修改指定标签中的内容

    javascript jquery 修改指定标签中的内容 $("#test1").text("Hello world!"); document.getEleme ...

  2. lqb 入门训练 序列求和 (PS:用长整数做数据的输入输出)

    入门训练 序列求和 时间限制:1.0s   内存限制:256.0MB     问题描述 求1+2+3+...+n的值. 输入格式 输入包括一个整数n. 输出格式 输出一行,包括一个整数,表示1+2+3 ...

  3. hdu 2516 取石子游戏 (Fibonacci博弈)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  4. Python常用模块之os.path

    os.path.abspath(path) 输入相对路径,返回绝对路径 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1 ...

  5. set map symbol

    set 声明 let set = new Set();即创建了一个空的set 赋值 let set = new Set(['张三','李四','王五']); 特性 似于数组,但它的一大特性就是所有元素 ...

  6. LF模式解决的问题

    一说起Leader/Followers并发模式,都会与Half-Async/Half-Sync并发模式进行比较,说LF模式更加高性能,成了一个高性能名词标签 符号,相反HA/HS仿佛成了一个低性能的名 ...

  7. k8s 随记

    1.kubelet参数解析:https://blog.csdn.net/qq_34857250/article/details/84995381 2.如何在github中查找k8s代码关键字? 现在我 ...

  8. 找到了element, 但是用getText却得到空值,取不到文本的解决办法

    最近代码中发现一些bug, 在Debug过程中发现,页面元素是被定位到了,但是用getText方法取到的却是空值.调查了一下发现,getText是否返回值和isDisplayed是否为true有关.当 ...

  9. 初探SpringMVC,走进SpringMVC的世界

    1.Springmvc入门 1.1.Springmvc是什么 SpringMVC是Spring中的一个组件,目前(2019)在互联网公司用的很多,是必需学习的一门框架技术!SpringMVC用于web ...

  10. java中的运算,+-* /% | ^ &

    java中运算都是操作符号,那么整形默认为int,双精度默认为都double 整数 看案例: 无法编译通过:操作默认为int,接受结果为int,所以这个地方编译无法通过,所以需要强制类型转换 再看案例 ...