题意:每次必须拿且只能拿不超过一半的石头,不能拿为败

思路:显然算出每个的sg函数,但是范围1e9显然不能直接打表。所以先打表找规律,发现偶数一直是自己的一半,奇数好像没规律。偶数x的sg函数值是x/2,说明前x/2~x-1的sg函数值涵盖了所有0~x/2集合的值,那么比他大1的奇数x+1少了x/2的sg函数值,那么x+1的sg函数值就是x/2的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 = + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
int main(){
int T, Case = ;
scanf("%d", &T);
while(T--){
ll ans = , n, a;
scanf("%lld", &n);
while(n--){
scanf("%lld", &a);
if(a & ){
while(a & )
a >>= ;
ans ^= a / ;
}
else ans ^= a / ;
}
if(ans)
printf("Case %d: Alice\n", Case++);
else
printf("Case %d: Bob\n", Case++);
}
return ;
}

打表代码:

#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 = + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
int sg[maxn], s[maxn];
void getSG(){
sg[] = ;
for(int i = ; i < maxn; i++){
memset(s, , sizeof(s));
for(int j = ; j <= i / ; j++){
s[sg[i - j]] = ;
}
for(int j = ; j < maxn; j++){
if(!s[j]){
sg[i] = j;
break;
}
}
}
}
int main(){
getSG();
for(int i = ; i < maxn; i++)
cout << i << " " << sg[i] << endl;
int T, Case = ;
scanf("%d", &T);
while(T--){
ll ans = , n, a;
scanf("%lld", &n);
while(n--){
scanf("%lld", &a);
ans ^= sg[a];
}
if(ans)
printf("Case %d: Alice\n", Case++);
else
printf("Case %d: Bob\n", Case++);
}
return ;
}

LightOJ 1296 Again Stone Game(sg函数)题解的更多相关文章

  1. LightOJ 1199 Partitioning Game(sg函数)题解

    题意:可以把一堆石子分成不相等的两堆,不能操作为败 思路:把一个石子拆成两个,变成了两个独立的游戏,mex里加上两者的sg异或.sg打表. 代码: #include<set> #inclu ...

  2. lightoj 1296 - Again Stone Game 博弈论

    思路:由于数据很大,先通过打表找规律可以知道, 当n为偶数的时候其SG值为n/2; 当n为奇数的时候一直除2,直到为偶数m,则SG值为m/2; 代码如下: #include<stdio.h> ...

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

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

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

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

  5. hdoj 1729 Stone Games(SG函数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1729 看了题目感觉像Nim,但是有范围限制,有点不知道SG函数该怎么写 看了题解,最后才明白该怎么去理 ...

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

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

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

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

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

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

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

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

随机推荐

  1. SpringBoot @Transactional声明事务无效问题

    查看系统支持的存储引擎:show engines; 查看表使用的引擎:show table status from db_name where name='table_name'; 修改表引擎方法:  ...

  2. LeetCode-104.Maxinum Depth of Binary Tree

    Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longe ...

  3. better-scroll一个好用的页面滑动工具

    1.npm install better-scroll   2.引入:import BetterScrol from 'better-scroll' 3. 在需要设置页面滚动的地方添加 ref=&qu ...

  4. SVN出现xcrun: error: invalid active developer path(Mac)

    Mac升级了系统,配置PHPStorm的SVN,出现如下错误: 具体提示的内容是:xcrun: error: invalid active developer path (/Library/Devel ...

  5. (转)Elasticsearch索引mapping的写入、查看与修改

    mapping的写入与查看 首先创建一个索引: curl -XPOST "http://127.0.0.1:9200/productindex" {"acknowledg ...

  6. Y2K Accounting Bug(poj2586)

    题意: 有一个公司由于某个病毒使公司赢亏数据丢失,但该公司每月的 赢亏是一个定数,要么一个月赢利s,要么一月亏d.现在ACM只知道该公司每五个月有一个赢亏报表,而且每次报表赢利情况都为亏.在一年中这样 ...

  7. ComBSTR的使用

    用 CComBSTR 进行编程 Visual Studio .NET 2003   3(共 3)对本文的评价是有帮助 - 评价此主题   ATL 类 CComBSTR 提供对 BSTR 数据类型的包装 ...

  8. [LeetCode] 88. Merge Sorted Array_Easy tag: Two Pointers

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: T ...

  9. Log Parser 2.2 + Log Parser Lizard GUI 分析IIS日志示例

    Log Parser 日志分析工具,用命令行操作,可以分析 IIS logs,event logs,active directory,log4net,file system,t-sql Log Par ...

  10. mysql buffer

    php与mysql的连接有三种方式,mysql,mysqli,pdo.不管使用哪种方式进行连接,都有使用buffer和不使用buffer的区别. 什么叫使用buffer和不使用buffer呢? 客户端 ...