题意:

  有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,

也可以选择将这堆石子分成任意的两堆。alice与bob轮流取,取走最后一个石子的人胜利。

思路:

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

打表代码

#include<cstdio>
#include<cstring>
int sg[];
int find(int x)
{
if(sg[x]>=) return sg[x];
bool mex[]= {};
for(int i=; i<x; i++)
{
mex[find(i)]=;//
if(x-i>&&i>) mex[find(i)^find(x-i)]=;
}
int i=;
while(mex[i]) i++;
return sg[x]=i;
}
int main()
{
int n;
memset(sg,-,sizeof(sg));//sg[0]=0;
//printf("%d#",sg[0]);
find();
for(int i=; i<=; i++) printf("%d %d\n",i,sg[i]);
return ;
}

提交代码:

#include<stdio.h>
int x[]={-,,,};
int main()
{
int _case,n,m,ans;
scanf("%d",&_case);
while(_case--)
{
ans=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&m);
ans^=m+x[m%];
}
if(ans)printf("Alice\n");
else printf("Bob\n");
}
}

hdu 3032 Nim or not Nim?(搜索打SG表)的更多相关文章

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

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

  2. hdu 3032 Nim or not Nim? sg函数 难度:0

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

  3. HDU 3032 Nim or not Nim (sg函数)

    加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...

  4. HDU 3032 Nim or not Nim? (sg函数求解)

    Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players ...

  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打表找规律)

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

  7. HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)

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

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

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

  9. HDU 3094 树上删边 NIM变形

    基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...

随机推荐

  1. 自学asp.net mvc(一)

    之前一直做asp.net的webform,现在想学习一下mvc,把自学中遇到的问题记录到博客. 一.codeplex上托管代码 1. 2. 3. 4. 5. 6. 7. 8. 9.

  2. Leetcode Variant-Plus N

    Given a non-negative number represented as an array of digits, plus N to the number. The digits are ...

  3. Bootstrap入门二:响应式页面布局

    Bootstrap 提供了一套响应式.移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列.它包含了易于使用的预定义类,还有强大的mixin 用于生成更具 ...

  4. mysql存储过程和游标以及if-else,while典型实例

    -- -------------------------------------------------------------------------------- -- Routine DDL - ...

  5. Class.forName("com.mysql.jdbc.Driver");的作用

    对于大的项目当然我们都已经有了原有基本框架,但是对于一些新的技术探讨的时候,我们还是直接调用Class.forName("com.mysql.jdbc.Driver")连接数据库进 ...

  6. java 多个设备,锁定先后顺序

    场景图: 4台android设备需要被锁定顺序,下次的时候按顺序socket推送数据到这4台不同的内容.当有新的一台机器加入时,如上图的E,则插入到原位置为C的地方.具体代码如下: public st ...

  7. throttle/debounce: 为你的cpu减减压(前端性能优化)

    何为throttle, 何为debounce? 谷歌翻译给出的意思:throttle 掐死???   debounce 去抖 好吧,按理解我们习惯翻译成 ——节流. 那么在什么场景下需要用到? 场景一 ...

  8. 第七周技术博客发表 web网页开发

    a<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org ...

  9. BZOJ1143 [CTSC2008] 祭祀river

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=1143 题目大意: 给你n个点,点与点之间由有向边相连.如果u能到达v的话,那么他们就不能同 ...

  10. Matlab梯度下降解决评分矩阵分解

    for iter = 1:num_iters %梯度下降 用户向量 for i = 1:m %返回有0有1 是逻辑值 ratedIndex1 = R_training(i,:)~=0 ; %U(i,: ...