题意:

有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆。alice与bob轮流取,取走最后一个石子的人胜利。

思路:

因为数的范围比较大,所以最好通过SG打表的结果找出规律在解。

sg(4k+1)=4k+1;sg(4k+2)=4k+2;sg(4k+3)=4k+4; sg(4k)=4k-1;

1 2 4 3 5 6 8 7

Sample Input
2
3
2 2 3
2
3 3

Sample Output
Alice
Bob

SG打表找规律

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# include <list>
# define LL long long
using namespace std ; int sg[];
bool vis[]; int mex(int n) //求N的SG值
{
if(sg[n] != -)return sg[n];
memset(vis,false,sizeof(vis));
for(int i=n-;i>=;i--)
{
vis[mex(i)]=;
}
for(int i=;i<=n/;i++)
{
vis[mex(i)^mex(n-i)]=;
}
for(int i = ;;i++)
if(vis[i] == false)
{
sg[n] = i;
break;
}
return sg[n];
} int main()
{ memset(sg,-,sizeof(sg));
for(int i = ;i <= ;i++)
sg[i] = mex(i);
int t , n ,x ; for(int i=;i<=;i++)
{
cout<<sg[i]<<" ";
if(i%==)
cout<<endl;
} return ;
}

题解代码

 # include <iostream>
# include <cstdio>
# include <cstring>
using namespace std ; int main ()
{
int T ;
scanf("%d" , &T) ;
while(T--)
{
int n ;
scanf("%d" , &n) ;
int x ;
int sum = ;
while(n--)
{
scanf("%d" , &x) ;
if (x % == )
sum ^= x ;
else if (x % == )
sum ^= x ;
else if (x % == )
sum ^= (x+) ;
else
sum ^= (x-) ;
}
if (sum == )
printf("Bob\n") ;
else
printf("Alice\n") ;
} return ;
}

HDU 3032 (SG打表找规律)的更多相关文章

  1. hdu 3032 sg打表找规律 *

    有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...

  2. HDU 3032 multi-sg 打表找规律

    普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...

  3. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  4. HDU 5976 Detachment 打表找规律

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5976 Detachment Time Limit: 4000/2000 MS (Java/Other ...

  5. HDU 3032 Nim or not Nim?(博弈,SG打表找规律)

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

  6. HDU 3032 Nim or not Nim?(SG打表找规律)

    题意: 给你n堆石子,你每次只能操作一堆石子 1.拿去任意个,最少1个 2.把这一堆分成两堆,没有要求对半分 解析+代码: 1 //解题思路: 2 //对于一个给定的有向无环图,定义关于图的每个顶点的 ...

  7. hdu 2147 kiki's game(DP(SG)打表找规律)

    题意: n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边. 无法移动硬币的人负. 给出n和m,问,先手胜还是后手胜. 数据范围: n, m (0<n ...

  8. A Simple Nim (SG打表找规律)

    题意:有n堆石子,每次可以将其中一堆分为数量不为0的3堆,或者从其中一堆中拿走若干个,最终拿完的那个人赢. 思路:直接暴力SG状态,然后找出其中的规律,异或一下每一堆的状态就可以了. #include ...

  9. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

随机推荐

  1. Hbase记录-HBase基本操作(一)

    HBase创建表 可以使用命令创建一个表,在这里必须指定表名和列族名.在HBase shell中创建表的语法如下所示. create ‘<table name>’,’<column ...

  2. JAVA记录-@Controller和RequestMapping注解代码介绍

    1.spring-mvc.xml加入配置 <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --> <context:component ...

  3. Linux重启服务器步骤

  4. Log4j Threshold属性指定输出等级

    有时候我们需要把一些报错ERROR日志单独存到指定文件 ,这时候,Threshold属性就派上用场了: Threshold属性可以指定日志level Log4j根据日志信息的重要程度,分OFF.FAT ...

  5. ObservableData-另一种姿势的观察者模式

    使用 数据的定义 public class TestModel { private static TestModel mInstance; public static TestModel GetIns ...

  6. Spring RedisTemplate操作-注解缓存操作(11)

    @Service @CacheConfig(cacheNames="user") public class RedisAn { public Map<String, User ...

  7. PB9.0数据窗口入门

    因为工作的关系,最近公司用PB比较多,至少10年没用过PB了,回顾一下数据窗口使用方法.1.代码结构 2.数据窗口 3.代码窗口代码 APP入口代码 4.需要使用DataBase插入一条数据 5.执行 ...

  8. tessaract ocr简介

    Tesseract的历史Tesseract是一个开源的OCR引擎,惠普公司的布里斯托尔实验室在1984-1994年开发完成.起初作为惠普的平板扫描仪的文字识别引擎.Tesseract在1995年UNL ...

  9. Mac下配置多个SSH KEY访问远程Git服务

    第一步 生成对应的ssh key 1 后面输入你的用户名 或者 邮箱 2 输入一个独立的ssh key名字 区别之前的名字 第二步  编辑 config文件 在.ssh/目录下面 在config文件配 ...

  10. Eclipse通用设置

    分类 Eclipse分为64位.32位,安装版.免安装版 查看Eclipse版本信息 Help - About Eclipse - Installation Details