LightOJ1199 Partition Game
Alice and Bob are playing a strange game. The rules of the game are:
- Initially there are n piles.
- A pile is formed by some cells.
- Alice starts the game and they alternate turns.
- In each tern a player can pick any pile and divide it into two unequal piles.
- 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的更多相关文章
- Partition:增加分区
在关系型 DB中,分区表经常使用DateKey(int 数据类型)作为Partition Column,每个月的数据填充到同一个Partition中,由于在Fore-End呈现的报表大多数是基于Mon ...
- Partition:Partiton Scheme是否指定Next Used?
在SQL Server中,为Partition Scheme多次指定Next Used,不会出错,最后一次指定的FileGroup是Partition Scheme的Next Used,建议,在执行P ...
- Partition:分区切换(Switch)
在SQL Server中,对超级大表做数据归档,使用select和delete命令是十分耗费CPU时间和Disk空间的,SQL Server必须记录相应数量的事务日志,而使用switch操作归档分区表 ...
- sql 分组取最新的数据sqlserver巧用row_number和partition by分组取top数据
SQL Server 2005后之后,引入了row_number()函数,row_number()函数的分组排序功能使这种操作变得非常简单 分组取TOP数据是T-SQL中的常用查询, 如学生信息管理系 ...
- Oracle Partition Outer Join 稠化报表
partition outer join实现将稀疏数据转为稠密数据,举例: with t as (select deptno, job, sum(sal) sum_sal from emp group ...
- SQLServer中Partition By 函数的使用
今天群里看到一个问题,在这里概述下:查询出不同分类下的最新记录.一看这不是很简单的么,要分类那就用Group By;要最新记录就用Order By呗.然后在自己的表中试着做出来: 首先呢我把表中的数据 ...
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- [LeetCode] Partition List 划分链表
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- 快速排序中的partition函数的枢纽元选择,代码细节,以及其标准实现
很多笔试面试都喜欢考察快排,叫你手写一个也不是啥事.我很早之前就学了这个,对快速排序的过程是很清楚的.但是最近自己尝试手写,发现之前对算法的细节把握不够精准,很多地方甚至只是大脑中的一个映像,而没有理 ...
随机推荐
- Linux常用命令复习
1> 查看文件信息:ls ls是英文单词list的简写,其功能为列出目录的内容,是用户最常用的命令之一,它类似于DOS下的dir命令. Linux文件或者目录名称最长可以有265个字符,“.”代 ...
- PHP 将数据从 Laravel 传送到 vue 的四种方式
在过去的两三年里,我一直在研究同时使用 Vue 和 Laravel 的项目,在每个项目开发的开始阶段,我必须问自己 “我将如何将数据从 Laravel 传递到 Vue ?”.这适用于 Vue 前端组件 ...
- java编程思想第四版第七章习题
(略) (略) (略) (略) 创建两个带有默认构造器(空参数列表)的类A和类B.从A中继承产生一个名为C的新,并在C内创建一个B类的成员.不要给C编写构造器.创建一个C类的对象并观察其结果. pac ...
- 并行模式之Master-Worker模式
并行模式之Master-Worker模式 一).Master-Worker模式 作用: 将一个大任务分解成若干个小任务,分发给多个子线程执行. 注: 将大任务分解成小任务,小任务的实现逻辑要相同. 二 ...
- RNN-LSTM讲解-基于tensorflow实现
cnn卷积神经网络在前面已经有所了解了,目前博主也使用它进行了一个图像分类问题,基于kaggle里面的food-101进行的图像识别,识别率有点感人,基于数据集的关系,大致来说还可行.下面我就继续学习 ...
- 使用Query Store监控性能
Query Store是SQL Server 2016中引入的语句性能监控和调优工具,它不仅自动捕获查询.执行计划和运行时统计信息的历史记录,而且还可以识别出由于执行计划更改而导致的性能差异,简化了性 ...
- Windows Server 2008 服务器重启后卡死在Windows Update 页面问题处理
Windows Update 服务器 服务器是联想RD640 操作系统Windows Server 2008 R2 Enterprise版 补丁版本是SP1 远程windows服务器时,一直处于远程建 ...
- echarts对柱状图进行标注,以及取消hover时的阴影
option = { color: ['#3398DB'], tooltip : { trigger: 'axis', axisPointer : { // 坐标轴指示器,坐标轴触发有效 type : ...
- 了解HTTP协议,这一篇就够了
HTTP(Hyper Text Transfer Protocol:超文本传输协议)是一个基于请求与响应模式的.无状态的.应用层的协议,常基于TCP的连接方式,HTTP1.1版本中给出一种持续连接的 ...
- mysql中给查询出的结果集添加自增序号
select (@i:=@i+1) i,emp.* from emp,(select @i:=0) it 按部门分组并按薪资总和从大到小排序求薪资总和第二高的部门名称和薪资总和:select c.en ...