题意:
    n堆石子,先拿光就赢,操作分为两种:
        1.任意一堆中拿走任意颗石子
        2.将任意一堆分成三小堆 ( 每堆至少一颗 )
        
分析:
    答案为每一堆的SG函数值异或和.
    故先打表寻找单堆SG函数规律.
    其中,若 x 可分为 三堆 a,b,c ,则 SG[x] 可转移至子状态 SG[a] ^ SG[b] ^ SG[c]  (三堆SG值异或和)
    
    打表后发现:
        SG[ 8*k - 1 ] = 8*k
        SG[ 8*k ] = 8*k - 1
        其余 SG[x] = x;
    
    则可直接得出答案

 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN = ;
int T, n;
int main()
{
scanf("%d", &T);
while ( T-- )
{
scanf("%d", &n);
int sg = ;
for (int i = ; i <= n; i++)
{
int x; scanf("%d", &x);
if (x % == ) sg ^= (x - ) ;
else if ( (x + ) % == ) sg ^= (x + ) ;
else sg ^= x;
}
if(sg) puts("First player wins.");
else puts("Second player wins.");
}
}
 /*
SG打表
*/
#include <iostream>
#include <cstring>
using namespace std;
int sg[];
int GetSG(int x)
{
if (sg[x] != -) return sg[x];
int vis[];
memset(vis, , sizeof(vis));
for (int i = ;i < x; i++)
vis[GetSG(i) ] = ;
int a,b,c;
for(a = ; a <= x; a++)
for(b = a; b <= x - a; b++)
for(c = b; c <= x - a - b; c++)
if(a+b+c == x)
vis[GetSG(a) ^ GetSG(b) ^ GetSG(c)] = ;
for(int i = ;; i++)
if(!vis[i]) return sg[x] = i;
}
int main()
{
memset(sg, -, sizeof(sg));
sg[] = ;
for (int i = ; i <= ; i++)
if(sg[i] == -) GetSG(i);
for(int i = ; i <= ; i++)
cout<<i<<" "<<sg[i]<<endl;
}

HDU 5794 - A Simple Nim的更多相关文章

  1. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5794 - A Simple Chess

    HDU 5794 - A Simple Chess题意: 马(象棋)初始位置在(1,1), 现在要走到(n,m), 问有几种走法 棋盘上有r个障碍物, 该位置不能走, 并规定只能走右下方 数据范围: ...

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

    A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...

  4. HDU 5794 A Simple Chess dp+Lucas

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 A Simple Chess Time Limit: 2000/1000 MS (Java/O ...

  5. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  6. HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  7. hdu 5795 A Simple Nim 博弈sg函数

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Pro ...

  8. HDU 5794 A Simple Chess (容斥+DP+Lucas)

    A Simple Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 Description There is a n×m board ...

  9. HDU 5794 A Simple Chess (Lucas + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5794 多校这题转化一下模型跟cf560E基本一样,可以先做cf上的这个题. 题目让你求一个棋子开始在( ...

随机推荐

  1. OC中限制UITextView的最大字数的实现

    一.属性 //自定义的textview @property (weak, nonatomic) IBOutlet UITextView *textview; //添加一个bool类型的属性 @prop ...

  2. Niagara AX之axvelocity的使用

    axvelocity是一个Web模板引擎模块,来源于Apache Velocity.由于我的Niagara AX的许可没有axvelocity,因此,在palette中没有找到axvelocity. ...

  3. css white-space

    以下是对上面几个属性的测试效果如下: 具体代码如下: <!DOCTYPE html> <html lang="en"> <head> <m ...

  4. HDU 1172 猜数字(DFS)

    猜数字 Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  5. Loadrunner11 录制手机App脚本多种方法介绍

    总体来说,通过LR录制手机脚本的方式有三种:1)通过代理方式录制,保证手机电脑在同一个网段:2)通过抓包录制,在手机上安装Mobile Recorder:3)通过安卓模拟器录制,本地安装Android ...

  6. swing的第一课

    Swing介绍 Swing API 可扩展 GUI组件,以减轻开发者的生活创造基于JAVA前端/GUI应用.它是建立在AWT API之上,并作为 AWTAPI 的更换,因为它几乎每一个控制对应 AWT ...

  7. POJ 2579 Fiber Network(状态压缩+Floyd)

    Fiber Network Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3328   Accepted: 1532 Des ...

  8. hdu 4649 Professor Tian 多校联合训练的题

    这题起初没读懂题意,悲剧啊,然后看了题解写完就AC了 题意是给一个N,然后给N+1个整数 接着给N个操作符(只有三种操作  即  或 ,与 ,和异或 |   &  ^ )这样依次把操作符插入整 ...

  9. UGUI Image控件

    今天一起学习Image控件O(∩_∩)O~ 介绍一下基本的属性 Source:Image:               指定图片源, 图片设置2DSprite(2D and UI)格式Color:   ...

  10. JFreeChart多坐标轴曲线图

    jar包:jcommon-1.0.23.jarjfreechart-1.0.19.jar maven配置: <dependency> <groupId>jfree</gr ...