HDU 3032 (SG打表找规律)
题意:
有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打表找规律)的更多相关文章
- hdu 3032 sg打表找规律 *
有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- HDU 5976 Detachment 打表找规律
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5976 Detachment Time Limit: 4000/2000 MS (Java/Other ...
- 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 ...
- HDU 3032 Nim or not Nim?(SG打表找规律)
题意: 给你n堆石子,你每次只能操作一堆石子 1.拿去任意个,最少1个 2.把这一堆分成两堆,没有要求对半分 解析+代码: 1 //解题思路: 2 //对于一个给定的有向无环图,定义关于图的每个顶点的 ...
- hdu 2147 kiki's game(DP(SG)打表找规律)
题意: n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边. 无法移动硬币的人负. 给出n和m,问,先手胜还是后手胜. 数据范围: n, m (0<n ...
- A Simple Nim (SG打表找规律)
题意:有n堆石子,每次可以将其中一堆分为数量不为0的3堆,或者从其中一堆中拿走若干个,最终拿完的那个人赢. 思路:直接暴力SG状态,然后找出其中的规律,异或一下每一堆的状态就可以了. #include ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
随机推荐
- Spark记录-SparkSQL相关学习
$spark-sql --help 查看帮助命令 $设置任务个数,在这里修改为20个 spark-sql>SET spark.sql.shuffle.partitions=20; $选择数据 ...
- Neural Networks and Deep Learning(week2)Logistic Regression with a Neural Network mindset(实现一个图像识别算法)
Logistic Regression with a Neural Network mindset You will learn to: Build the general architecture ...
- postgresql时间处理
时间取到截取 例:select date_trunc('second', "reportTime") from travel_message limit 10; 结果: 他人博客: ...
- 第16月第31天 mongo
1. 94 brew install mongodb 95 cd ~ 96 cd Desktop/web/ 97 ls 98 mkdir mongo 99 cd mongo/ 100 ...
- C#中富文本编辑器Simditor带图片上传的全部过程(MVC架构的项目)
描述:最近c#项目中使用富文本编辑器Simditor,记录一下以便以后查看. 注:此项目是MVC架构的. 1.引用文件 项目中引用相应的css和js文件,注意顺序不能打乱,否则富文本编辑器不会正常显示 ...
- vue pc端网站项目开发坑点与难度记录
背景 在一pc端的web项目里,由于某些特性需要由动态语言处理,所以只在有需要使用vue来处理数据的页面,直接引入vue.js来处理.由于刚开始并没有打算使用前端来渲染数据和处理交互,所以使用了一些非 ...
- mysql 架构~MGR监控手段
一 简介 今天咱们来聊聊MGR的监控 二 监控 方面: 1 节点mysql进程监控 2 节点mysql复制进程的监控 ...
- Mybatis进阶学习笔记——输出映射
输出映射(例如一个方法的返回至使用什么类型去接收) 1.基本类型 <!-- 统计记录数 --> <select id="queryTotalCount" resu ...
- 【Ehcache】ehcache2.5.2缓存的使用
缓存的名字是ehcache...老是记得是encache.... 官方PDF文档:http://www.ehcache.org/documentation/ehcache-2.5.x-document ...
- Cpp读文件、CString转String、String转CString
场景 C++读取文件 技术点 读取文件 fstream提供了三个类,用来实现c++对文件的操作.(文件的创建.读.写). ifstream -- 从已有的文件读入 ofstream -- 向文件写内容 ...