题意:可以把一堆石子分成不相等的两堆,不能操作为败

思路:把一个石子拆成两个,变成了两个独立的游戏,mex里加上两者的sg异或。sg打表。

代码:

#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
typedef long long ll;
const int maxn = 1e4 + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
int sg[maxn], s[maxn];
int main(){
sg[] = ;
for(int i = ; i < maxn; i++){
memset(s, , sizeof(s));
for(int j = ; j * < i; j++){
s[sg[j] ^ sg[i - j]] = ;
}
for(int j = ; j < maxn; j++){
if(!s[j]){
sg[i] = j;
//cout << j << endl;
break;
}
}
}
int T, Case = ;
scanf("%d", &T);
while(T--){
int n;
scanf("%d", &n);
ll ans = ;
while(n--){
ll a;
scanf("%lld", &a);
ans ^= sg[a];
}
if(ans) printf("Case %d: Alice\n", Case++);
else printf("Case %d: Bob\n", Case++);
}
return ;
}

LightOJ 1199 Partitioning Game(sg函数)题解的更多相关文章

  1. LightOJ 1229 Treblecross(SG函数打表 + 遍历)题解

    题意:给你一串含“.”和“X”的字串,每次一个玩家可以把‘."变成“X”,谁先弄到三个XXX就赢.假如先手必赢,输出所有能必赢的第一步,否则输出0. 思路:显然如果一个X周围两格有X那么肯定 ...

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

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

  3. 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 ...

  4. LightOJ 1296 Again Stone Game(sg函数)题解

    题意:每次必须拿且只能拿不超过一半的石头,不能拿为败 思路:显然算出每个的sg函数,但是范围1e9显然不能直接打表.所以先打表找规律,发现偶数一直是自己的一半,奇数好像没规律.偶数x的sg函数值是x/ ...

  5. 题解——牛客网Wannafly挑战赛23 B-游戏 (SG函数)

    前言 比赛的时候没学过SG函数的蒟蒻以为是道结论题,但是不是QwQ 和dummyummy巨佬一起推了快三个小时的规律 最后去问了真正的巨佬__stdcall __stdcall面带微笑的告诉我们,这是 ...

  6. LightOJ 1315 - Game of Hyper Knights(博弈sg函数)

    G - Game of Hyper Knights Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...

  7. POJ 2425 A Chess Game(有向图SG函数)题解

    题意:给一个有向图,然后个m颗石头放在图上的几个点上,每次只能移动一步,如果不能移动者败 思路:dfs打表sg函数,然后求异或和 代码: #include<queue> #include& ...

  8. ZOJ 2083 Win the Game(SG函数)题解

    题意:给一端n块的板,两人玩,每次能涂相邻两块没涂过的板,不能涂的人为输,先手赢输出yes 思路:sg函数打表,练习题 代码: #include<queue> #include<cs ...

  9. HDU 1848 Fibonacci again and again(SG函数入门)题解

    思路:SG打表 参考:SG函数和SG定理[详解] 代码: #include<queue> #include<cstring> #include<set> #incl ...

随机推荐

  1. LoadRunner-参数化(添加参数值)

    录制完脚本后,想要对脚本重复使用需要对某些值设定为参数,如accounts和password. 1.选中需要参数化的accounts值,点击右键->选择Replace with a parame ...

  2. react-native run-android error: unknown host service

    D:\rnworkspace\Hello>react-native run-android JS server already running.Running D:\Android\sdk/pl ...

  3. Unity 补充安装

    当需要下载 安装Unity之时没勾选的一些组件时, 1.去Unity官网点开Unity旧版本 2.找到你的Unity版本,然后只要下载Unity安装程序 3.点开安装程序,去掉已安装组件的勾选,勾选你 ...

  4. [kx]宇宙-银河

    行星/恒星/卫星的区分 目前太阳系内有8颗行星,分别是:水星.金星.地球.火星.木星.土星.天王星.海王星. 参考 恒星是自发光,而行星(行星通常指自身不发光,其公转方向常与所绕恒星的自转方向相同.) ...

  5. POJ1860:Currency Exchange(BF)

    http://poj.org/problem?id=1860 Description Several currency exchange points are working in our city. ...

  6. turple list dict 互相转换

    1. 字典(dict) dict = {'name': 'Zara', 'age': 7, 'class': 'First'} 1.1 字典---字符串 print (type(str(dict)), ...

  7. 关于DOM2级事件的事件捕获和事件冒泡

    DOM2级事件中addEventListener的执行机制,多个addEventListener同时添加时的执行先后规律: W3C的DOM事件触发分为三个阶段:①.事件捕获阶段,即由最顶层元素(一般是 ...

  8. 全文搜索引擎Xapian

    安装过程 安装xapian-core wget http://oligarchy.co.uk/xapian/1.0.13/xapian-core-1.0.13.tar.gztar zxvf xapia ...

  9. C# Bulk Operations(转)

    转自http://blog.csdn.net/winnyrain/article/details/51240684 Overcome SqlBulkCopy Limitations with C# B ...

  10. PKU2418_树种统计(map应用||Trie树)

    Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nu ...