传送门

1199 - Partitioning Game
Time Limit: 4 second(s) Memory Limit: 32 MB

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

Output for Sample Input

3

1

4

3

1 2 3

1

7

Case 1: Bob

Case 2: Alice

Case 3: Bob

Explanation

In case 1, Alice has only 1 move, she divides the pile with 4 cells into two unequal piles, where one pile has 1 cell and the other pile has 3 cells. Now it's Bob's turn. Bob divides the pile with 3 cells into two piles, where one pile has 1 cell and another
pile has 2 cells. So, now there are three piles having cells 1, 1, 2. And Alice loses, since she doesn't have any moves now.


题目大意:

有n堆石子(1<=n<=100),每一堆分别有ai个石子(1<=ai<=10000),一次操作能够使一堆石子变成两堆数目不相等(注意是不相等)的石子,最后不能操作就算输,问先手赢还是后手赢。

解题思路:

就是一个SG函数,提到SG函数这个就是求一下 当前状态的下一个状态,又由于 这 n 堆石子是相互独立的,没有影响 所以说 能够开用SG函数,

依据SG定理,如果 当前堆中有 m块石子 那么他的下一状态就可能有 {1,m-1},{2,n-2},...,{(m-1)/2,m-(m-1)/2}(把每一种情况都想到
而且分析出来)。

然后分完的那些 a和b块石子又能够进行分,以此类推。那么SG(x) = mex{ SG(1)^SG(x-1), SG(2)^SG(x-2),...,
SG((x-1)/2)^SG(x-(x-1)/2) },

然后我们要求的就是 SG[a[0]]^SG[a[1]]^...^SG[a[n-1]],假设结果是0就是 后手赢,否则 先手赢

My Code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 10000+5;
int sg[MAXN];
int hash[MAXN];
void Get_sg()///模板
{
memset(sg, 0, sizeof(sg));
for(int i=1; i<MAXN; i++)
{
memset(hash, 0, sizeof(hash));
for(int j=1; j*2<i; j++)
{
hash[sg[j]^sg[i-j]] = 1;
}
int j;
for(j=0; j<MAXN; j++)
if(!hash[j])
break;
sg[i] = j;
}
}
int main()
{
Get_sg();
int T;
scanf("%d",&T);
for(int cas=1; cas<=T; cas++)
{
int m, sum = 0;
scanf("%d",&m);
for(int i=0; i<m; i++)
{
int x;
scanf("%d",&x);
sum ^= sg[x];
}
if(sum)
printf("Case %d: Alice\n",cas);
else
printf("Case %d: Bob\n",cas);
}
return 0;
}

LIGHT OJ 1199 - Partitioning Game的更多相关文章

  1. Light OJ 1199 - Partitioning Game (博弈sg函数)

    D - Partitioning Game Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  2. Light OJ 1199:Partitioning Game(SG函数模板)

    Alice and Bob are playing a strange game. The rules of the game are: 1.      Initially there are n p ...

  3. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  4. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  5. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  6. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  7. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  8. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

  9. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

随机推荐

  1. PHPCMS标签

    获取栏目名:{$CAT[catname]}或{$catname}获取父栏目名:{$CATEGORYS[$CAT[parentid]][catname]} 获取同级栏目列表: {pc:content a ...

  2. SpringBoot添加对Log4j2的支持

    1.在添加对Log4j2的支持前,需要先把SpringBoot默认使用的Logback日志框架排除,修改pom.xml文件: <dependency> <groupId>org ...

  3. JAVA中使用Apache HttpComponents Client的进行GET/POST请求使用案例

    一.简述需求 平时我们需要在JAVA中进行GET.POST.PUT.DELETE等请求时,使用第三方jar包会比较简单.常用的工具包有: 1.https://github.com/kevinsawic ...

  4. 当前Azure中国可使用的虚拟机的Size列表

    Standard_A0,Standard_A1,Standard_A2,Standard_A3,Standard_A5,Standard_A4,Standard_A6,Standard_A7, Bas ...

  5. AngularJS实现三级Table列表

    angular.module('yo03App') .controller('MyrouteCtrl', function ($scope) { $scope.professors = [{ 'nam ...

  6. POSTGRESQL表分区

    最近发现POSTGRESQL的一张表(下面统称为test表)达到67G大小,不得不进行重新分区,下面记录一下步骤: 前言.查看数据表结构(表结构肯定是虚构的) CREATE TABLE test ( ...

  7. unable to find the sources of your current Linux kernel.

    运行 sh ./VBoxLinuxAdditions.run 时FAILED,查看日志: /tmp/vbox.0/Makefile.include.header:97: *** Error: unab ...

  8. Aerospike系列:2:商业版和社区版的比较

    http://www.aerospike.com/products-services

  9. Webwork【08】结合实战简析Controller 配置

    虽然现在 MVC 框架层出不穷,但做为 Struts 前身的 webwork. 其经典程度不亚于贝利之于足球,双 11 之于淘宝特卖. 本篇将结合 webwork controller 配置文件 xw ...

  10. cocos2d-js V3.0 V3.1使用DragonBones

    DragonBones是Adobe支持的一个开源项目,用于制作和播放骨骼动画,官网地址是:http://dragonbones.effecthub.com/.DragonBones首先在Flash和S ...