Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains some stone. Alice stars the game and they alternate moves. In each move, a player has to select any pile and should remove at least one and no more than half stones from that pile. So, for example if a pile contains 10 stones, then a player can take at least 1 and at most 5 stones from that pile. If a pile contains 7 stones; at most 3 stones from that pile can be removed.

Both Alice and Bob play perfectly. The player who cannot make a valid move loses. Now you are given the information of the piles and the number of stones in all the piles, you have to find the player who will win if both play optimally.

Input

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

Each case starts with a line containing an integer n (1 ≤ n ≤ 1000). The next line contains n space separated integers ranging in [1, 109]. The ith integer in this line denotes the number of stones in the ith pile.

Output

For each case, print the case number and the name of the player who will win the game.

Sample Input

5

1

1

3

10 11 12

5

1 2 3 4 5

2

4 9

3

1 3 9

Sample Output

Case 1: Bob

Case 2: Alice

Case 3: Alice

Case 4: Bob

Case 5: Alice

题意

有n堆石子,每堆ai个,Alice和Bob两人取石子,可以任选一堆取,每次至少一个至多ai/2个(奇数情况向下取整)。最后不能取石子的人失败

思路

数据范围1e9,肯定不能打表计算,但是可以打表来找一下规律。最后会发现,如果ai是偶数的话,可以把这堆石子看成ai/2个石子进行取,如果是奇数,就让ai一直除以2,至到找到偶数,然后再按照石子数是偶数的情况处理一下就可以了

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int SG[1005], mex[1005];
int sg[maxn];
int vis[maxn];
int a[maxn];
inline void getSG()
{
ms(sg);
for(register int i=1;i<=maxn;i++)
{
ms(vis);
for(int j=1;2*j<=i;j++)
vis[sg[i-j]]=1;
for(register int j=0;j<=maxn;j++)
{
if(!vis[j])
{
sg[i]=j;
break;
}
}
cout<<i<<"======="<<sg[i]<<endl;
}
}
int main(int argc, char const *argv[])
{
// getSG();
ios::sync_with_stdio(false);
register int t;
register int _=0;
register int n;
cin>>t;
while(t--)
{
register int sum=0,x;
cin>>n;
while(n--)
{
cin>>x;
while(x%2!=0)
x/=2;
x/=2;
sum^=x;
}
cout<<"Case "<<++_<<": ";
if(sum)
cout<<"Alice"<<endl;
else
cout<<"Bob"<<endl;
}
return 0;
}

Light OJ 1296:Again Stone Game(SG函数打表找规律)的更多相关文章

  1. bzoj 1228 [SDOI2009]E&D SG函数打表 找规律

    题目链接 Description 桌子上有2n 堆石子,编号为1..2n.将第2k-1 堆与第2k 堆(1 ≤ k ≤ n)为同一组.第i堆的石子个数用一个正整数Si表示.一次分割操作指的是,从桌子上 ...

  2. hdu 3032 Nim or not Nim? (sg函数打表找规律)

    题意:有N堆石子,每堆有s[i]个,Alice和Bob两人轮流取石子,可以从一堆中取任意多的石子,也可以把一堆石子分成两小堆 Alice先取,问谁能获胜 思路:首先观察这道题的数据范围  1 ≤ N ...

  3. Playing With Stones UVALive - 5059 Nim SG函数 打表找规律

    Code: #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll ...

  4. 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

    打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...

  5. Light OJ 1296 - Again Stone Game (博弈sg函数递推)

    F - Again Stone Game Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

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

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

  7. 【博弈论】【SG函数】【找规律】Gym - 101147A - The game of Osho

    以后这种题还是不能空想,必须打个表看看,规律还是比较好找的……具体是啥看代码.用SG函数暴力的部分就不放了. #include<cstdio> using namespace std; i ...

  8. Nim or not Nim? hdu3032 SG值打表找规律

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. Educational Codeforces Round 68 (Rated for Div. 2)D(SG函数打表,找规律)

    #include<bits/stdc++.h>using namespace std;int sg[1007];int main(){ int t; cin>>t; while ...

随机推荐

  1. 转:Linux环境变量设置方法总结 PATH、LD_LIBRARY_PATH

    转:  https://www.linuxidc.com/Linux/2017-03/142338.htm 文章写比较全  转载记录 Linux环境变量设置方法总结 PATH.LD_LIBRARY_P ...

  2. Win10系列:UWP界面布局基础7

    2.附加属性 有一些XAML元素,其自身的属性大多是在其它的元素中声明和使用的,该元素本身却很少使用,这些在其他元素中声明和使用的属性被称为附加属性(Attached Properties).附加属性 ...

  3. nexus下载远程maven中央仓库的解决方案

    参考:http://www.linuxidc.com/Linux/2014-03/98708.htm https://repo.maven.apache.org/maven2/.index/ 下载这两 ...

  4. commons-logging 与log4j的关系

    参考:http://zachary-guo.iteye.com/blog/361177

  5. day27 网络通信协议 tcp/udp区别

    今日主要内容: 一.网络通信协议 二.tcp udp协议下的socket 一.网络通信协议 1.1互联网的本质就是一系列的网络协议 本机IP地址('127.0.0.1',xxxx) 互联网连接的电脑互 ...

  6. pytorch加载和保存模型

    在模型完成训练后,我们需要将训练好的模型保存为一个文件供测试使用,或者因为一些原因我们需要继续之前的状态训练之前保存的模型,那么如何在PyTorch中保存和恢复模型呢? 方法一(推荐): 第一种方法也 ...

  7. 进程创建过程详解 CreateProcess

    转载请您注明出处:http://www.cnblogs.com/lsh123/p/7405796.html 0x01 CreateProcessW CreateProcess的使用有ANSI版本的Cr ...

  8. Ubuntu16.04 安装Teamviewer

    有时需要远程控制ubuntu系统的电脑,Teamviewer在linux下也可以进行安装,大致看了下向日葵在linux下配置好像比较麻烦,而且Teamviewer远程控制的流畅性一直不错,就选择安装T ...

  9. 『翻译』Android USB Host

    USB Host When your Android-powered device is in USB host mode, it acts as the USB host, powers the b ...

  10. shell脚本实例-批量检查多个网站地址是否正常

    #!/usr/bin/bash [ -f /etc/init.d/functions ] && . /etc/init.d/functions array=( http://www.w ...